473,699 Members | 2,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to disable a multiple selection control using javascript

I have a script like below:

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

<html>
<head>
<title>TEST</title>
<script language="javas cript>
<!--
function masking () {
var aForm = window.document .aForm;
if (aForm.build_ty pe.value == "A")
aForm.selected_ ae.disabled = true;
else
aForm.selected_ ae.disabled = false;
}
// -->
</script>
</head>
<body>
<form method="post" name="aForm">
<select name="build_typ e" size=1 onchange="maski ng()">
<option value="A">STD</option>
<option value="B">NON-STD</option>
</select>
<select name="selected_ ae[]" size="3" multiple>
<option value="james">J ames</option>
<option value="john">Jo hn</option>
<option value="jimmy">J immy</option>
<option value="jason">J ason</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
2 4526
gg****@gmail.co m 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="javas cript>
<script type="text/javascript">
<!--
Don't use this
function masking () {
var aForm = window.document .aForm;
if (aForm.build_ty pe.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_typ e" size=1 onchange="maski ng()">


<select name="build_typ e" size="1" onchange="maski ng(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
Thanks a lot for your help, Matt.
It really works!!!

Feb 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3022
by: Joe Helmick | last post by:
This one has me really stumped, so I thought I'd ask publicly. I was trying to take my ASP.NET web page "template" -- banner graphic, small navigation bar, and user feedback message area -- and make it into a user control. I wanted to stretch one of the graphics so it always went all the way across the browser window. So far, so good... And then, I wanted to take the two-cell table that holds the naviagation bar and make it always...
1
1632
by: john | last post by:
I have two different problems: 1. When the user has clicked on a button that is causing the browser to post back to the server, it could take a little while for the new page to show up. So in the mean time, I want to change the cursor to an hourglass and disable all of the controls on the form using javascript so the user can't do anything with any of the controls on the page. But when I disable certain controls (e.g. text boxes, radio...
1
1081
by: Eric Caron | last post by:
Hi everybody, I have a form where I have checkbox that triggers javascript code to make a div appear. This is when the user selects "Other" in the list of choices and we ask him to specify his choice using a textbox control. Now if the user has selected the "Other" choice, the entry of the information in the textbox is mandatory, so I want to be able to enable the RequiredFieldValidator associated with the field. In the event when the...
8
5728
by: Adam | last post by:
Hey, I'm using JS to submit a form with image submit buttons, using the following code... (Page is here... http://www.cards2do.co.uk/addcard.php?card_id=292 ) ************************************************************************************** <form action="https://www.cards2do.co.uk/addcard.php" method="post"
1
2182
by: Leszek | last post by:
Hi I have user-side javascript that validates a form. And I have server-side php script thad does the same. Is it possible to disable php script from showing messages about missing values if javascrpt did it before?? i have <div id='wrong"></div> that contains these messages. So I tried to set style.display='none' but it seems that it doesn't work. I guess this is because javascript first sets style.display='none' but it
2
3171
by: kplkumar | last post by:
I have created a asp.net date picker control using Javascript. I wanted to do this to avoid doing post back when the calendar window is launched. It works like charm. But the challenge is - the control does not use any asp.net controls like button or textfield. It uses html "input" for the text field and the button. So after the user has choosen the date and the date is populated in the textfield, I am not able to get the value from the...
1
2391
by: gopalpawar7 | last post by:
how to disable Save as option using java script?
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8908
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4374
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.