IntelliJ Java IDE
The moose likes HTML, CSS and JavaScript and the fly likes making validation on combo box having dynamic name Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "making validation on combo box having dynamic name" Watch "making validation on combo box having dynamic name" New topic
Author

making validation on combo box having dynamic name

Rekha Pande
Ranch Hand

Joined: Jan 29, 2004
Posts: 145
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..!
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 411
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

Joined: Jan 29, 2004
Posts: 145
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

Joined: Feb 02, 2001
Posts: 411
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

Joined: Jan 29, 2004
Posts: 145
Thanx yuriy... i understood it now...! thank you..!
 
 
subject: making validation on combo box having dynamic name
 
Threads others viewed
browser back button problem.
Displaying record from combo box
dynamic text boxes
Selecting a value in a combo box that equals the value from the database record?
problem with display tag
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture