admin管理员组文章数量:1410689
I have the following code where 2 drop downs are available on the UI. When I select value "1" of drop down 1, the drop down 2 should be disabled. When I select value "1", the dropdown 2 is disabled. But I am not able to re-enable the drop down 2 when the user select value "2" from drop down 1. I am not sure since I am calling the performValidation()
method for onClick
event of both the options in drop down 1.
Code:
<html>
<head></head>
<script = "text/javascript">
function performValidation()
{
if (document.mainForm.criteriaOne.value == "1")
{
document.mainForm.criteriaTwo.options.length = 0;
document.mainForm.criteriaTwo.disabled = true;
}
else
document.mainForm.criteriaTwo.disabled = false;
}
</script>
<body>
<form name="mainForm" action= "" method ="get">
Criteria One:<select id = "criteriaOne">
<option value = "1" onClick ="performValidation()"> Select One - One</option>
<option value = "2" onClick ="performValidation()"> Select one - Two</option>
</select>
Criteria Two:<select id = "criteriaTwo">
<option value = "1" onClick ="performValidation()"> Select Two - One</option>
</select>
</form>
</body>
</html>
I have the following code where 2 drop downs are available on the UI. When I select value "1" of drop down 1, the drop down 2 should be disabled. When I select value "1", the dropdown 2 is disabled. But I am not able to re-enable the drop down 2 when the user select value "2" from drop down 1. I am not sure since I am calling the performValidation()
method for onClick
event of both the options in drop down 1.
Code:
<html>
<head></head>
<script = "text/javascript">
function performValidation()
{
if (document.mainForm.criteriaOne.value == "1")
{
document.mainForm.criteriaTwo.options.length = 0;
document.mainForm.criteriaTwo.disabled = true;
}
else
document.mainForm.criteriaTwo.disabled = false;
}
</script>
<body>
<form name="mainForm" action= "" method ="get">
Criteria One:<select id = "criteriaOne">
<option value = "1" onClick ="performValidation()"> Select One - One</option>
<option value = "2" onClick ="performValidation()"> Select one - Two</option>
</select>
Criteria Two:<select id = "criteriaTwo">
<option value = "1" onClick ="performValidation()"> Select Two - One</option>
</select>
</form>
</body>
</html>
Share
asked Mar 24, 2011 at 19:59
name_maskedname_masked
9,82344 gold badges124 silver badges174 bronze badges
1
- Not sure, your code works for me as is in Firefox 4.0 – Duniyadnd Commented Mar 24, 2011 at 20:18
2 Answers
Reset to default 2You need to wire up a function to the onchange event on the select something like
document.getElementById("criteriaOne").onchange = function()
{ // do some work to check the selectedIndex and determine whether to re- enable the other drop down}
You don't necessarily need
document.mainForm.criteriaTwo.options.length = 0;
本文标签: htmlEnableDisable dropdownJavascriptStack Overflow
版权声明:本文标题:html - EnableDisable dropdown - Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744827649a2627160.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论