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.
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.
Share Improve this question edited Nov 29, 2017 at 16:30 TylerH 21.1k77 gold badges79 silver badges112 bronze badges asked Aug 18, 2013 at 21:14 crazyim5crazyim5 7142 gold badges9 silver badges26 bronze badges 2 |1 Answer
Reset to default 26I guess that this will work for you.
if(document.getElementById('selectid').value == "val1") {
//Do something
}
True != true
. – elclanrs Commented Aug 18, 2013 at 21:15if(document.getElementById('selectid').value=='val1')
– nnnnnn Commented Aug 18, 2013 at 21:16