Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
188
rated 0 times [  193] [ 5]  / answers: 1 / hits: 89248  / 11 Years ago, sun, august 18, 2013, 12:00:00

If I have a select like this



<select id=selectid name=selectname onchange=jsfunc1()>
<option value=val1 id=valid1> Val1 </option>
<option value=val2 id=valid2> Val2 </option>
<option value=val3 id=valid3> Val3 </option>
</select>


I now have a javascript function func2, say, that need to do something if option val1 is selected. How do I do that?



For example,



function func2(){
....
if(document.getElementById('valid2').selected==True){
//Do something
}
}


I'm not getting the exact syntax right and that's where I need your help.


More From » html

 Answers
5

I guess that this will work for you.



if(document.getElementById('selectid').value == val1) {
//Do something
}

[#76292] Friday, August 16, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryder

Total Points: 473
Total Questions: 110
Total Answers: 91

Location: Northern Ireland
Member since Mon, Nov 14, 2022
2 Years ago
;