How to disable a multiple selection control using javascript

G

ggk517

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>
 
M

Matt Kruse

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>


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top