• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

making validation on combo box having dynamic name

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi...
I have a while loop in which loops through a number of records .. now supposing my while loop has fetched 5 records ..then in the <TD> i will have 5 combo box one below the other ... the name of the combo are:
while(rs.next)
{
combo = combo+1;
}
so the name of the 5 combo boxes is combo1,combo2,combo3,combo4,combo5...same if their are 10 combo then the name will go till combo10....
I have the intial value of the combo box as select . ... now in the java script how will i validate on these dynamic combos ... making sure that the user doesn't leave the value of any of the combo as "select" ???

any ideas .....
thanxs in advance..!
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use
var sl = document.getElementsByTagName("select");
for(var i=0;i<sl.length;i++){
if(sl[i].name.indexOf("combo") == 0){
.... validate it .....
}
}
Also, it mught make sense to have all comboboxes named the same.
than you will do
var sl = document.getElementsByName("combo");
and no need for check inside the loop.
If you use JSP, on a server you do
String[] combos = request.getParameterValues("combo").
thanks, Yuriy
 
Rekha Pande
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all..
yuriy.... since i'm not too good with java script i yet don't understand the technicality that lies behind it.... can u tell me what does this getElementsbyTagname mean...???
i didn't quite understand.....!!!
and for this loop .. .......
for(var i=0;i<sl.length;i++){
if(sl[i].name.indexOf("combo") == 0){
.... validate it .....
}
}
sl[i].name.indexOf("combo") == 0 ..... the value that is there in the quote ...i.e. "combo"..is it the name of the combo box.....if it so ... then how will i know the name of the combo box as the name is dynamic..!!!
please do tell..!!!
thanxs a lot..!
 
Yuriy Fuksenko
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getElementsByTagName function returns you array of pointers to elements of specified tag. In our case - array of pinters to all SELECT elements on a page. I am assuming not all of them are the once you are looking for.
Even though names for your elements are dynamic, you bulding it somehow.
from your example your select elements always have a name starting with prefix "combo" - combo1, combo2 .... This is what that indexOf checks.
So if select elemnt have a name starting with "combo" - you validate it.
 
Rekha Pande
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx yuriy... i understood it now...! thank you..!
 
You don't like waffles? Well, do you like this tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic