473,320 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

30
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="JavaScript"> function updateCheckBox () {
selectedItem = form1.scrp_arw.options [form1.scrp_arw.selectedIndex].value;
if (selectedItem != '') {
form1.scrp_home_cz.checked=true; form1.scrp_home_cz.disabled=true; }
else {
form1.scrp_home_cz.disabled=false form1.scrp_home_cv.checked=false;
}
}
updateCheckBox ();
</script>
Mar 30 '07 #1
8 10159
acoder
16,027 Expert Mod 8TB
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
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 100+
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
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
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 100+
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 Expert Mod 8TB
I have merged the threads because they were on the same topic.

Did you solve your problem?
Apr 2 '07 #8
cptuser
30
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
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...
3
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...
0
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...
5
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...
1
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...
6
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...
3
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...
19
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...
1
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.