473,666 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check & Disable a check box based on a dropdown menu options

30 New Member
Hi,

I've put together this javascript taken from various sources, but i think it is wrong or missing something. If particular options are selected within a drop down menu, then the check botton will auto check and disable (grey out) at the same time. If seems like if will work fine but int he database it will wont show as selected, but if I manually check it, it will record fine in the DB so the form works, but not the javascript. Here is the code. i need help - i have no idea what is wrong.

<script language="JavaS cript"> function updateCheckBox () {
selectedItem = form1.scrp_arw. options [form1.scrp_arw. selectedIndex].value;
if (selectedItem != '') {
form1.scrp_home _cz.checked=tru e; form1.scrp_home _cz.disabled=tr ue; }
else {
form1.scrp_home _cz.disabled=fa lse form1.scrp_home _cv.checked=fal se;
}
}
updateCheckBox ();
</script>
Mar 30 '07 #1
8 10174
acoder
16,027 Recognized Expert Moderator MVP
Welcome to TSDN.

This may be a typo, but if the javascript is on one line, you should have a semi-colon. After the 'disabled=false ', you have a semi-colon missing.
Mar 30 '07 #2
cptuser
30 New Member
I put the semi colon in and it did not make any different. I actually had it in the original code but when I pasted in my post above I forgot to add it.

Do you have any other suggestions? Would it have somoething to do with the fact that there are two things happening to the same field at the same time and it can't handle it properly, would there be a better way to write the javascript, for example combine the action (check & disable) at the same time rather than seperate them?
Mar 30 '07 #3
chunk1978
224 New Member
Would it have somoething to do with the fact that there are two things happening to the same field at the same time and it can't handle it properly...
nope... i'm pretty sure this is not the reason... try this:

Expand|Select|Wrap|Line Numbers
  1. <script language="text/JavaScript">
  2.  
  3. function updateCheckBox ()
  4.      {
  5.      var selectedItem = form1.scrp_arw.options[form1.scrp_arw.selectedIndex].value;
  6.      if (selectedItem!="")
  7.      {form1.scrp_home_cz.checked=true; form1.scrp_home_cz.disabled=true;}
  8.      else 
  9.      {form1.scrp_home_cz.disabled=false; form1.scrp_home_cv.checked=false;}
  10. }
  11. </script>
  12.  
and i'm pretty sure you also need to define in your HTML code weather your checkbox is initially Checked/Unchecked and Disabled/Enabled for the javascript to use true and false...
Apr 1 '07 #4
cptuser
30 New Member
nope... i'm pretty sure this is not the reason... try this:
It's not working for me. I would like to try it another way. If the checkbox is checked, then the dropdown menu is enabled. If the checkbox is NOT checked then the dropdown menu is Disabled. I don't know what the whole javascript would be. Hope you can help me.
Apr 1 '07 #5
cptuser
30 New Member
Anyone can share javascript code for this, please.

If a checkbox is checked (default is unchecked), then a drop down list below it is enabled (that is not greyed out, the default is disabled – greyed out). If the user then unchecks the checkbox, then 2 things happen to the drop down menu, it is disabled (greyed out) and it’s value changes to an option with a value of nothing “”.

Hope someone can assist. I have not idea.
Apr 1 '07 #6
chunk1978
224 New Member
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <script type="text/javascript">
  5. function EnableSelectMenu()
  6.     {
  7.     if (document.getElementById('Checkbox').checked)
  8.     {document.getElementById('SelectMenu').disabled=false}
  9.     else
  10.     {document.getElementById('SelectMenu').disabled=true}
  11. }
  12. </script>
  13.  
  14. </head>
  15.  
  16. <body>
  17. <form action="" method="get">
  18.   <p>
  19.     <input type="checkbox" name="Checkbox" id="Checkbox" value="checkbox" onClick="EnableSelectMenu();">
  20. Check To Enable Select Menu </p>
  21.   <p>
  22.     <select name="SelectMenu" id="SelectMenu" disabled="disabled">
  23.       <option value="SelectionA">Selection A</option>
  24.       <option value="SelectionB">Selection B</option>
  25.       <option value="SelectionC">Selection C</option>
  26.     </select></p>
  27.   </form>
  28. </body>
  29. </html>
  30.  
Apr 1 '07 #7
acoder
16,027 Recognized Expert Moderator MVP
I have merged the threads because they were on the same topic.

Did you solve your problem?
Apr 2 '07 #8
cptuser
30 New Member
Yes it did thank you.
Apr 2 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

12
1773
by: CJM | last post by:
I've had some periodic problems on certain (intranet)servers where IIS seems to be caching thing in an unexpected way, or is server cached pages where new content is expected. The first situation is where we have a standard Top + Left + Content framset; the left frame contains a menu which shows standard options - when the user logs in, extra menu options are available to them, depending on their priveleges. The menu is generated from a...
3
2125
by: ACaunter | last post by:
Hi there, can someone please tell me what the easiest way to have a dropdown menu bar positioned on the screen (eg. Home, company, ... , contact us) then when the mouse goes over then, the sub menu options are displayed thanks a lot -- AdamPC@hotmail.com
0
2502
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that don't work nearly as well as they should, even for analysts and power users. The reason they haven't reached the masses is because most of the tools are so difficult to use and reveal so little
5
3582
by: balu435 | last post by:
Hi friends, I have an (VBA) application which programatically fills the options in a web page. I have an dropdown menu whose options are selected during run-time by using a function.Is there anyway by which I can select the option in the dropdown menu programatically? If the dropdown menu had its options explicitily mentioned (like <option value="1">1</option>...) I could have used document.form.objectname.selectedindex=n But here all I...
1
9682
by: William Youngman | last post by:
I have a gridview displaying data and would like to use the AJAX dropdown extender so that when the user clicks on a record a dropdown menu will display providing the user with a menu of selections to choose from (yes much like the SharePoint 2007 dropdown menu). I'm having problems dynamically binding the 'TargetControlID' property of the extender control to the record label in the gridview. What I'm doing is - The label's text is the...
6
3740
by: rakeshvthu | last post by:
hi all, can we disable the copy and paste option in edit menu bar of browser my customer does not want copying using any technique so can any one help how to disable that options copy and paste in menu bar using java script urgently required loooking for quick response
3
6280
by: bhanubalaji | last post by:
hi, I am unable to disable the text(label) in javascript..it's working fine with IE,but i am using MOZILLA.. can any one help regarding this.. What's the wrong with my code? I am sending my code here.. Thanks in Advance... Regards
19
3675
by: Jim | last post by:
Hi, I have two questions/problems pertaining to CSS horizontal dropdown menus and am hoping that someone here can help me out. (1) I'm having a problem centering the menu. I picked up the code for this from a tutorial but that menu was flush-left justified. Not what I want. Subsequent searches on google on how to center yielded a
1
5047
by: ibeehbk | last post by:
HI. I have a dropdown menu named arrivalcity (options are Rome, Naples, Palermo, and CAtania). I also have 4 other dropdown menus which have departure dates for those cities. Basically I want those 4 dropdown menus disabled by default. Then based on which arrivalcity option they choose only one of those 4 dropdown menus gets enabled so they can select the departure date from the appropriate menu. I know this can get accomplished in...
0
8440
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
8352
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8549
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
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7378
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5661
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
4192
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
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1763
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.