This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Radio Validator Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Radio Validator" Watch "Radio Validator" New topic
Author

Radio Validator

Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
Hi ranchers,

Below code attempts to validate the Gender radio button.
The error is that the objGender.length is undifined. Could you give me some help? Thanks.



SCJP 1.4 SCJD
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2896
    
    1

"id" name must be unique one in whole HTML page. You just repeated 'txtGender' twice. Correct it.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56208
    
  13

After you fix your id problem, you can save yourself lot of code by using jQuery on your pages for things like this.

To check that one of the radio buttons is checked, the code would simply be:


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
I removed the ID, and correct to . And then the code can work as I expect.
Thanks.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Radio Validator
 
Similar Threads
Form does not validated correctly
Validate
document.forms[0].submit(); throws Invalid Argument in IE
Retain selected content in a JSP
jQuery validation and radio buttons