By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,034 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,034 IT Pros & Developers. It's quick & easy.

How to disable a multiple selection control using javascript

P: n/a
I have a script like below:

------------------------------------------------------------------------------------------------------------------------

<html>
<head>
<title>TEST</title>
<script language="javascript>
<!--
function masking () {
var aForm = window.document.aForm;
if (aForm.build_type.value == "A")
aForm.selected_ae.disabled = true;
else
aForm.selected_ae.disabled = false;
}
// -->
</script>
</head>
<body>
<form method="post" name="aForm">
<select name="build_type" size=1 onchange="masking()">
<option value="A">STD</option>
<option value="B">NON-STD</option>
</select>
<select name="selected_ae[]" size="3" multiple>
<option value="james">James</option>
<option value="john">John</option>
<option value="jimmy">Jimmy</option>
<option value="jason">Jason</option>
</select>
</form>
</body>
</html>

------------------------------------------------------------------------------------------------------------------------

I tried to disable a multiple selection control using Javascript but it
did not work. Can anyone please help me? Thanks in advance for your
help.

Feb 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
gg****@gmail.com wrote:
I tried to disable a multiple selection control using Javascript but
it did not work. Can anyone please help me? Thanks in advance for your
help.
Several things need fixed:
<script language="javascript>
<script type="text/javascript">
<!--
Don't use this
function masking () {
var aForm = window.document.aForm;
if (aForm.build_type.value == "A")
aForm.selected_ae.disabled = true;
else
aForm.selected_ae.disabled = false;
}
function masking(o) {
var isA = (o.options[o.selectedIndex].value=="A");
o.form.elements['selected_ae[]'].disabled = isA;
}
// -->
Don't use this
<select name="build_type" size=1 onchange="masking()">


<select name="build_type" size="1" onchange="masking(this)">

Make the above changes and your code will both work and be better written.
Hope that helps.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Feb 27 '06 #2

P: n/a
Thanks a lot for your help, Matt.
It really works!!!

Feb 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.