|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Assigning various list boxes to the same code
if (document.form1.select_class_year3.options[0].selected )
{ for (i = 1; i<=document.form1.select_class_year3.length; i++ ) { if ( document.form1.select_class_year3.options[i].selected ) { alert("You cannot select 'All' and another option. Please Unselect the rest."); return false; } } } return true; I am having around 15 list boxes in my page. I need to use the above code for each. I am using the above code in the onChange event of each list box, so that it wouldn’t allow me to choose two options if the option all as represented by the code options[0] above. I want to make the above code generic to all the listboxes. The above code has a specific list box ‘select_class_year3’. I don’t want to write the same code for every list box. Is there a way I could get all the names of the list boxes in a variable and loop in one by one so that the above code would apply to all list boxes ? Does Java Script allow such kind of coding? Thank You. |
|
#2
|
||||
|
||||
|
try 'this':
function check(obj) { if (obj.options[0].selected) { .... } } call with: <select onchange='check(this)'> |
|
#3
|
|||
|
|||
|
Thanks a lot.
Quote:
|
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > Assigning various list boxes to the same code |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|