473,569 Members | 2,751 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 1015
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
9418
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 intercept the key so that I can do stuff on the server side to make the new window behave correctly? (We have a JSP-based webapp which stores state in...
53
5672
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 difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
6
2265
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 as computer hardware, configuration, etc... down to the lowest level (e.g. BIOS, assembly language, etc). Anyway, I've obviously got something...
136
9250
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 code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to...
0
7694
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...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6278
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...
1
5504
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
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...
0
3651
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...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
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...

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.