473,387 Members | 1,619 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.

Inline error with radio buttons

fieryscream
This is the javascript code that i have for validating a form, it raises error if the user puts in invalid information. The problem im having is when i enter:
Expand|Select|Wrap|Line Numbers
  1. /*  if(title.checked=false){
  2.   inlineMsg('radio', 'You must select a title.',2);
  3.   return false;
  4.   */
it brakes the code, but when i comment out the rest works fine?????

Expand|Select|Wrap|Line Numbers
  1. function validate(form) {
  2.   var name = form.name.value;
  3.   var email = form.email.value;
  4.   var title = form.title.value;
  5.   var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  6.   var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  7.   var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  8. /*  if(title.checked=false){
  9.   inlineMsg('radio', 'You must select a title.',2);
  10.   return false;
  11.   }*/
  12.   if(name == "") {
  13.     inlineMsg('name','You must enter your name.',2);
  14.     return false;
  15.   }
  16.   if(!name.match(nameRegex)) {
  17.     inlineMsg('name','You have entered an invalid name.',2);
  18.     return false;
  19.   }
  20.   if(email == "") {
  21.     inlineMsg('email','<strong>Error</strong><br />You must enter your email.',2);
  22.     return false;
  23.   }
  24.   if(!email.match(emailRegex)) {
  25.     inlineMsg('email','<strong>Error</strong><br />You have entered an invalid email.',2);
  26.     return false;
  27. }
  28.  
  29.   return true;
  30. }
HTML
Here is Html for the radio buttons
Expand|Select|Wrap|Line Numbers
  1.     <label>Mr:
  2.         <input name="title"  value="Mr"  type="radio" />
  3.       </label>
  4.       <label> Ms:
  5.         <input name="title" value="Ms" type="radio" />
  6.       </label>
  7.       <label> Mrs:
  8.         <input name="title"  value="Mrs" type="radio" />
  9.       </label>
  10.       <label> Dr:
  11.         <input name="title" value="Dr" type="radio" />
  12.       </label>
Sep 2 '09 #1
5 3148
Dormilich
8,658 Expert Mod 8TB
@fieryscream
a less error-prone approach to if conditions:
Expand|Select|Wrap|Line Numbers
  1. if ("value" == variable)
if you’re incidentally using the assignment operator (=), there will be an error thrown
Sep 2 '09 #2
yup i have tried the == ... but is still not works ?
Sep 3 '09 #3
Dormilich
8,658 Expert Mod 8TB
what does the error state?
Sep 3 '09 #4
um i got it to work in the end
however i had to make the focus of the error on another element
so i was thinking of making an invisible element next to the radio buttons in order to make the message appear next to them.

So ... how do i make a text box be invisible?
Sep 6 '09 #5
acoder
16,027 Expert Mod 8TB
The error was caused by this line:
Expand|Select|Wrap|Line Numbers
  1. var title = form.title.value;
It's got the value of the radio button, not the button itself.

To hide an element, set its display property to "none" (to remove from the flow) or its visibility to "hidden".
Sep 6 '09 #6

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

Similar topics

4
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1>...
6
by: Craig Keightley | last post by:
I have a page that has n number of radio groups (yes/No) how can i prevent the form being submitted if more than one radio group is not selected? By default all radio groups are unchecked ...
7
by: michael | last post by:
apologies in advance, as not only am i new to learning how to code javascript properly, i'm new to the groups posting thing... i am developing in firefox 1.0+, but will be working in an msie 6.0+...
30
by: Will Pittenger | last post by:
Does C# inline functions? I do not see a inline keyword. Is there an implicit inline? Can the compiler select functions for auto-inlining? I am more used to C++ where all these things are...
2
by: James P. | last post by:
Help, I need to display radio buttons on a form. The data is from SQL table: each row in each table is displayed as a radio button. I have multiple SQL tables so I understand I need to put...
1
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
3
by: cpnet | last post by:
I have a GridView which I'm populating from an ObjectDataSource (give the GridView a DataTable). The GridView will have about 20 rows, and only one editable column. The editable column consists...
2
by: dpazza | last post by:
Hi, I'm creating a quiz on using a form in VB 2005 express. I have four sets of questions and answers (labels and radio buttons) and I change between which set of questions is currently shown on...
7
by: gengyue | last post by:
Hi, I am running a report using Cold Fusion. This report is generated by cfloop tag. Depends on the record count of a query, the report will list the data retrieved from the database. each row in...
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: 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: 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?
0
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
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...

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.