473,387 Members | 1,492 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,387 software developers and data experts.

Javascript - Disabled and Re-enable select form element

30
Hi,

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() {
  2.  
  3. var vfullearly = document.getElementById('fullearly').value;
  4.  
  5. if (vfullearly = 1)
  6.     {
  7.         document.getElementById('fullnorm').disabled=true;
  8.  
  9.     }
  10. else if (vfullearly = 0)
  11.     {
  12.         document.getElementById('fullnorm').disabled=false;
  13.     }
  14.  
  15. }
The HTML form:


Expand|Select|Wrap|Line Numbers
  1. <form>
  2.  
  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 20422
omerbutt
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
acoder
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
cptuser
30
Terrific thanks!
"=" means set
"==" means compare
May 2 '09 #4
acoder
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

30
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
3
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
3
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...
1
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...
1
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; //...
1
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...
0
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: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.