Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / February 2006



Tip: Looking for answers? Try searching our database.

How to disable a multiple selection control using javascript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ggk517@gmail.com - 27 Feb 2006 15:26 GMT
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.
Matt Kruse - 27 Feb 2006 16:40 GMT
> 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;
[quoted text clipped - 3 lines]
>         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.

Signature

Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com

ggk517@gmail.com - 28 Feb 2006 15:56 GMT
Thanks a lot for your help, Matt.
It really works!!!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.