473,231 Members | 2,872 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,231 software developers and data experts.

Javascript - Disabled and Re-enable select form element


I have an online form which has a select element, which I;m using very basic JS to enable and disable a select element based on the selection of another select element.

For some reason, the JS disables the select element correctly, but it does not re-enable it. Could someone please help with the right code.

here is the Javascript code.

Expand|Select|Wrap|Line Numbers
  1. function annconf() {
  3. var vfullearly = document.getElementById('fullearly').value;
  5. if (vfullearly = 1)
  6.     {
  7.         document.getElementById('fullnorm').disabled=true;
  9.     }
  10. else if (vfullearly = 0)
  11.     {
  12.         document.getElementById('fullnorm').disabled=false;
  13.     }
  15. }
The HTML form:

Expand|Select|Wrap|Line Numbers
  1. <form>
  3. Price early: 
  4.   <label>
  5.     <select name="Full, Early Bird" id="fullearly" onchange="annconf();">
  6. <option value="0">No</option>
  7. <option value="1">Yes</option>
  8. </select>
  9.   </label>
  10. </p>
  11. <p> Price Normal: 
  12.   <select name="Full, Normal" id="fullnorm">
  13.     <option value="0">No</option>
  14.     <option value="1">Yes</option>
  15.   </select>
  16. <form>
May 2 '09 #1
4 20412
638 512MB
have a look@ this one mybe it will help
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>Untitled</title>
  5. <script language="JavaScript" type="text/javascript">
  6. <!--
  7. function checkSel(selName,selIndex,val,val2){
  8. if(selName=="sel1"&&selIndex!=0){
  9. document.forms[0]['sel'+val].disabled=false;
  10. }
  11. if(selName=="sel1"&&selIndex==0){
  12. document.forms[0]['sel'+val].disabled=true;
  13. document.forms[0]['sel'+val2].disabled=true;
  14. document.forms[0]['sel'+val].selectedIndex=0;
  15. document.forms[0]['sel'+val2].selectedIndex=0;
  16. }
  17. if(selName=="sel2"&&selIndex!=0){
  18. document.forms[0]['sel'+val].disabled=false;
  19. }
  20. if(selName=="sel2"&&selIndex==0){
  21. document.forms[0]['sel'+val].disabled=true;
  22. document.forms[0]['sel'+val].selectedIndex=0;
  23. }
  24. }
  25. //-->
  26. </script>
  27. </head>
  28. <body>
  29. <form>
  30. <select name="sel1" onchange="checkSel(this.name,this.selectedIndex,2,3)">
  31. <option>select</option>
  32. <option>blah1_1</option>
  33. <option>blah1_2</option>
  34. <option>blah1_3</option>
  35. </select>
  36. <select name="sel2" disabled onchange="checkSel(this.name,this.selectedIndex,3)">
  37. <option>select</option>
  38. <option>blah2_1</option>
  39. <option>blah2_2</option>
  40. <option>blah2_3</option>
  41. </select>
  42. <select name="sel3" disabled>
  43. <option>select</option>
  44. <option>blah3_1</option>
  45. <option>blah3_2</option>
  46. <option>blah3_3</option>
  47. </select>
  48. </form>
  49. </body>
  50. </html> 
May 2 '09 #2
16,027 Expert Mod 8TB
The problem in your code, cptuser, is that in this line, for example
Expand|Select|Wrap|Line Numbers
  1. if (vfullearly = 1)
you're setting instead of comparing. Use double equals to compare:
Expand|Select|Wrap|Line Numbers
  1. if (vfullearly == 1)
May 2 '09 #3
Terrific thanks!
"=" means set
"==" means compare
May 2 '09 #4
16,027 Expert Mod 8TB
Yep, that's correct :)
May 2 '09 #5

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

Similar topics

by: Mason A. Clark | last post by:
If I use javascript on my page, how likely is it that the viewer will not have javascript? Anyone have data? Mason C
by: rodchar | last post by:
hey all what if a user has javascript disabled on their machine and your .Net app uses javascript. What is the workaround or workthru thanks in advance rodchar
by: Steve Murphy | last post by:
When JavaScript is disabled on FireFox, the selection and paging controls on my DataGrids stop working. Am I doing something wrong here, or are these controls tied to JavaScript? Thanks in...
by: Frankie | last post by:
Just doing some testing here to see what happens when JavaScript is disabled. I was told somewhere along the line that PostBacks would fail because they rely on JavaScript: function...
by: gatejs | last post by:
In IE. If you use the back button, the resulting page will execute the javascript in the page again: In Firefox, whatever value a variable had is kept when you go back to it: var i=0; //...
by: eraimondi | last post by:
Is there a way in asp to check if a client has javascript disabled? I know that the object MSWC.BrowserType retrieves a bool value that determine if browser client supports Javascript but not if is...
by: Schemed | last post by:
Hello All, I have been searching for the accepted manner of providing web UI functionality with Javascript disabled. Assuming I am not missing a third way, the two methods I can think of are: ...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.