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

how to validate radio button and drop down list using java script?

127 100+
Form:

Expand|Select|Wrap|Line Numbers
  1. <form name="newuserForm" action="register.php" method="post" onsubmit="return validateForm()";>
  2.  
  3. <label style="font-size:18px">Gender<br />
  4. </label><label style="font-size:18px">Male </label><input id="male" type="radio" name="gender" class="box" style="border:solid 3px #333333" value="female" />
  5. <label style="font-size:18px">أنثى</label><input id="female" type="radio" name="gender" value="female"><br /><br />
  6.  
Java Script:
Expand|Select|Wrap|Line Numbers
  1. function validateForm()
  2. {
  3. if (document.getElementById("male").checked=false && document.getElementById("female").checked=false)
  4. {
  5.      alert("Please select Gender");
  6.   return false;
  7. }
  8. }
its not working? how to do it? please help....
Jun 17 '13 #1
1 4226
Atli
5,058 Expert 4TB
A single = is an assignment operator, while double == is a comparison operator. If you are checking whether two values match, you should use the double version.

Expand|Select|Wrap|Line Numbers
  1. // This is wrong. This will not check if it's false, it will
  2. // set it to false and then return true.
  3. if (value = false)
  4.  
  5. // This is how it should be.
  6. if (value == false)
  7.  
  8. // Or, since this is a boolean check, you can also do this.
  9. if (!value)
  10.  
Jun 17 '13 #2

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

Similar topics

3
by: John Morgan | last post by:
I am using a database to populate a drop down list using myDropDownList.DataSource = myCmd.ExecuteReader myDropDownList.DataBind() That works alright and a few lines later in the code I wish...
1
by: Bishop | last post by:
I made a GridView with a Drop Down List using the example here: http://www.orcsweb.com/articles/dotnet_control_templates.aspx It appears to work except that it dosn't actually save the updated...
6
by: nishtr | last post by:
Can any one told me that how can i format the drop down list using CSS
2
by: subhashk | last post by:
Is it possible to create editable drop down list using ASP.NET?
1
by: subhashk | last post by:
Is it possible to create a editable HTML drop down list using javascript?
1
by: Shimna Thomas | last post by:
Plz help me by providing the code to bind a drop down list using C#.
11
by: ajaymohank | last post by:
Hello Friends....... in my project i am having a dropdown and based on the values selected from the dropdown, i have to enable 2 radio button. in the on change function of drop down i have written...
7
by: coolnags | last post by:
Hi, As we know IE SELECTdrop down list has limitations on tool tip on individual option items and also horizontal scroll bar. Can any one please tell any other alternative to show the tool...
4
by: sstock9983 | last post by:
I am in a class right now where the students are making an information system in Access. Right now we are at a point where we are finalizing our forms. We need to find a way to create a new item in a...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.