473,503 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript problem

63 New Member
hi i have trouble with disabled the select list when any of checkboxes is not checked and enable if one of them is checked this is my code
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--
  3.  function Select()
  4.      {
  5.      if (document.getElementById('one').checked )
  6.      {document.getElementById('class').disabled=false
  7.      }
  8.   if else (document.getElementById('two').checked )
  9.   {document.getElementById('class').disabled=false}
  10.     if else
  11.      {document.getElementById('class').disabled=true}
  12.  }
  13. //-->
  14. </script>
  15. p> 2. Which our classes have you attended?<br/>
  16. <input type="checkbox" name="classes"  value="1" id="one"  onclick="Select(this);" /> Aerobics</br>
  17. <input type="checkbox" name="classes"  value="2"  id="two"  onclick="select(this);"  /> Boxing<br/>
  18. <input type="checkbox" name="classes" value="3"   id="three"  onclick="select(this);"  /> Circuit Class<br/>
  19. <input type="checkbox" name="classes"  value="4"   id="four"  onclick="select(this);"  /> Weight Training </p>
  20.  
  21. <p> 3. Which of the above classes has been <b> most</b> beneficial for you?<br/>
  22. (You can only choose one from list)
  23. <select name="class" id="class" disabled="true" size="1"  style="color:#FFFFFF; background-color:#8A2BE2">
  24. <option value="Choose"> - -Please Choose- -  </option>
  25. <option value="AER">Aerobics</option>  
  26. <option value="Box">Boxing</option>
  27. <option value="Circuit">Circuit Class</option>
  28. <option value="Weight">Weight Training</option></select></p>
Apr 2 '09 #1
3 1013
chaarmann
785 Recognized Expert Contributor
Javascript is not java, you were in the wrong forum. And use code-tags around your code. And you are messing with lowercase-uppercase function names (Select() vs. select()). That's why it doesn't work. Javascript and Java are case sensitive. And you can't just revert "else if". If the syntax is wrong, then javascript doesn't work at all! (you can see a small error sign in the corner of your browser). This is incontrast to HTML, where you miss an opening bracket from your <p> tag and it still works, skipping the unreadable tag. Just enable your javascript debugger (e.g. firebug in firefox), it will tell you the lines that are wrong.

General tip: just edit a few lines only first and get it working with. Then add more. Add line, test, add line, test, and so on.
You can't just type a whole full-blown program without testing and then expect it to work immediately.
Apr 2 '09 #2
Dormilich
8,658 Recognized Expert Moderator Expert
swap "if" and "else" on lines 8 and 10 to get a valid if-elseif-else construct.

[edit] darn, missed by seconds ;)

you can also use "this" inside the function to simplify matters
Expand|Select|Wrap|Line Numbers
  1.  function Select()
  2. {
  3.      if (this.checked)
  4.      {
  5.           document.getElementById('class').disabled = false;
  6.      }
  7.  }
Apr 2 '09 #3
lolodede
63 New Member
thanks alot its working now
Apr 2 '09 #4

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

Similar topics

13
9396
by: Kai Grossjohann | last post by:
It seems that Ctrl-N in Mozilla opens a new empty browser window. That's fine, I don't need to do anything about it. But Ctrl-N in IE appears to clone the current window. Is there a way to...
53
5656
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
6
2256
by: Alex Rast | last post by:
First of all, this is not a programming question. I'm a user, not programming in JavaScript. I'm not, however, a novice user or even a power user - I certainly know programming intimately as well...
136
9201
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
0
7198
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
7072
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...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7319
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...
1
6979
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...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
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 ...
0
373
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...

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.