|
-
March 3rd, 2005, 09:46 PM
#1
disable one option of <select> list
here is what i have: i have two <SELECT> lists - select1 and select2. what the JavaScript function does is disable select2 if "Summary" is chosen from select1. And here is what i need - when "Summary" is chosen from select1 i don't want to disable select2 but disable one of the options(let's say "two") of select2. sounds simple enough but i have not been able to get solid help on other forums. thanks.
<html>
<body>
<script language="JavaScript">
<!--
function disable()
{
var indice = document.frm.select1.selectedIndex;
//var optionDESC = document.frm.select2.options[1];
if(document.frm.select1.options[indice].value=="Summary")
{
document.frm.select2.disabled=true;
}
else
{
document.frm.select2.disabled=false;
}
}
-->
</script>
<form name="frm">
<select name="select1" onchange="disable()">
<option value="Detail">Detail</option>
<option value="Summary">Summary</option>
</select>
<br><br>
<select name="select2">
<option value="1">one</option>
<option value="2">two</option>
</select>
</form>
</body>
</html>
-
March 4th, 2005, 08:47 AM
#2
Re: disable one option of <select> list
You should be able to use something like removeChild something like
Code:
document.frm.select2.removeChild(document.frm.select2.options[1]);
The alternative would be to keep 2 different versions of select2 in your document, always keep one disabled and switch between the two, when "Summary" is selected/deselected in select1.
The biggest problem encountered while trying to design a system that was completely foolproof,
was, that people tended to underestimate the ingenuity of complete fools.
Douglas Adams
-
March 4th, 2005, 01:01 PM
#3
Re: disable one option of <select> list
Thanks KHP, it does the trick except it removes the child completely and does not return it when other than "summary" is reselected from select1. But i'll have to tweak it a little bit. Thanks again.
-
March 4th, 2005, 02:25 PM
#4
Re: disable one option of <select> list
Yes, you do of course have to add it to the select, when summary is deselected, you can use the insertBefore method for this http://www.mozilla.org/docs/dom/domr...7.html#1028897 , to do that you will of course have to maintain a reference to the deletede option, in the javascript when you delete it.
The biggest problem encountered while trying to design a system that was completely foolproof,
was, that people tended to underestimate the ingenuity of complete fools.
Douglas Adams
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|