| 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
|
|
|