What's wrong with this code? When I change first select to International It disables the second select. but when I'm select Local it doesn't enable the second select
<script type="text/javascript">
function changetextbox()
{
if (document.getElementById("LocalOrInternations").value == "International") {
document.getElementById("NormalOrPaper").disabled='true';
}
else
document.getElementById("NormalOrPaper").disabled='false';
}
</script>
<span class="input-group-addon" id="basic-addon1">Local Or International</span>
<select name="LocalOrInternations" id="LocalOrInternations" onChange="changetextbox();" class="form-control">
<option value="Local">Local</option>
<option value="International">International</option>
</select>
<span class="input-group-addon" id="basic-addon1">Normal Or Paper Seminar></span>
<select name="NormalOrPaper" id="NormalOrPaper" class="form-control">
<option value="Normal">Normal</option>
<option value="Seminar">Seminar</option>
</select>
'false'
and 'true'
are strings . When coerced to boolean, they're both true
(because any string that isn't blank is "truthy".) You want the actual booleans false
and true
(no quotes).
if (document.getElementById("LocalOrInternations").value == "International") {
document.getElementById("NormalOrPaper").disabled = true;
// -------------------------------------------------^^^^
}
else {
document.getElementById("NormalOrPaper").disabled = false;
// -------------------------------------------------^^^^^
}
Side note: I recommend being consistent with your {}
. Either include them around single statements (as you did with the if
), or don't (as you did with the else
), but don't sometimes include them around single statements and not other times.
you have to remove '
from the boolean tag.
you have to set like this.
<script type="text/javascript">
function changetextbox()
{
if (document.getElementById("LocalOrInternations").value == "International") {
document.getElementById("NormalOrPaper").disabled=true;
}
else
document.getElementById("NormalOrPaper").disabled=false;
}
</script>
check this jsfiddle: click here
这应该有帮助
document.getElementById("NormalOrPaper").removeAttribute('disabled');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.