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

Validating radio

Hi all,

I have a dynamically generated page that can have 1 or more radio buttons. I
am using javascript with onsubmit in the form statement to make sure a radio
button is selected before allowing the page to be submitted. At the moment
it only works when there is 2 or more radio buttons on the page.

How can I get the radio button validation working when there is only 1 radio
on the page ?
Many thanks, Blinky.

Nov 29 '05 #1
6 3107
Blinky wrote on 29 nov 2005 in comp.lang.javascript:
I have a dynamically generated page that can have 1 or more radio
buttons. I am using javascript with onsubmit in the form statement to
make sure a radio button is selected before allowing the page to be
submitted. At the moment it only works when there is 2 or more radio
buttons on the page.

How can I get the radio button validation working when there is only 1
radio on the page ?


Radio buttons should according to specs always be in a group with one
selected. some browsers accept bad html programming with zero selected, but
unselecting by the user is never possible.

That is why having only one radio button in a form is senseless.

Use checkboxes for your purpose.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Nov 29 '05 #2
Thanks Evertjan,

I cannot use checkboxes as I cannot have more then one item selected. My
problem is when a search returns only 1 result. Even if this one result is
checked the validation code still does not validate it. What do you think I
can do instead ?

Cheers, Blinky.

"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.242...
Blinky wrote on 29 nov 2005 in comp.lang.javascript:
I have a dynamically generated page that can have 1 or more radio
buttons. I am using javascript with onsubmit in the form statement to
make sure a radio button is selected before allowing the page to be
submitted. At the moment it only works when there is 2 or more radio
buttons on the page.

How can I get the radio button validation working when there is only 1
radio on the page ?


Radio buttons should according to specs always be in a group with one
selected. some browsers accept bad html programming with zero selected,
but
unselecting by the user is never possible.

That is why having only one radio button in a form is senseless.

Use checkboxes for your purpose.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Nov 29 '05 #3
Blinky wrote:
I cannot use checkboxes as I cannot have more then one item selected.
My problem is when a search returns only 1 result. Even if this one
result is checked the validation code still does not validate it.
What do you think I can do instead ?


If your search returns only 1 result, why not mark it as CHECKED by default?

Otherwise, validating radio buttons needs to be slightly different depending
on if it's a collection of objects or a single object. A general lib like
http://www.JavascriptToolbox.com/validations/ will allow you to get input
values regardless of the number of inputs you have with the same name.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Nov 29 '05 #4
Blinky wrote:
Thanks Evertjan,

I cannot use checkboxes as I cannot have more then one item selected. My
problem is when a search returns only 1 result. Even if this one result is
checked the validation code still does not validate it. What do you think I
can do instead ?


Please don't top post. Reply below trimmed, quoted text.

A single radio button doesn't make sense. They should only be used if
there are two or more. Why not use a checkbox if there is only one
result and radios if 2 or more?

[...]

--
Rob
Nov 29 '05 #5
JRS: In article <il*****************@news-server.bigpond.net.au>, dated
Tue, 29 Nov 2005 13:04:14 local, seen in news:comp.lang.javascript,
Blinky <xx***********@bigpond.net.au> posted :
I have a dynamically generated page that can have 1 or more radio buttons. I
am using javascript with onsubmit in the form statement to make sure a radio
button is selected before allowing the page to be submitted. At the moment
it only works when there is 2 or more radio buttons on the page.
So you need to change your validation code.
How can I get the radio button validation working when there is only 1 radio
on the page ?


With dynamic material, you may legitimately have only one line of the
button-deserving type. If you count them before you generate them, you
can omit the button if there's only one line.

Alternatively, you can have a permanent Button Zero, selected by
default, labelled "none of them"; and validate by checking that it is
cleared.

But your code is wrong.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Nov 30 '05 #6

"Dr John Stockton" <jr*@merlyn.demon.co.uk> wrote in message
news:X1**************@merlyn.demon.co.uk...
JRS: In article <il*****************@news-server.bigpond.net.au>, dated
Tue, 29 Nov 2005 13:04:14 local, seen in news:comp.lang.javascript,
Blinky <xx***********@bigpond.net.au> posted :
I have a dynamically generated page that can have 1 or more radio buttons.
I
am using javascript with onsubmit in the form statement to make sure a
radio
button is selected before allowing the page to be submitted. At the moment
it only works when there is 2 or more radio buttons on the page.


So you need to change your validation code.
How can I get the radio button validation working when there is only 1
radio
on the page ?


With dynamic material, you may legitimately have only one line of the
button-deserving type. If you count them before you generate them, you
can omit the button if there's only one line.

Alternatively, you can have a permanent Button Zero, selected by
default, labelled "none of them"; and validate by checking that it is
cleared.

But your code is wrong.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of
news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates,
sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items,
links.


Thanks everyone,

I have changed my code and validate server side now.
Cheers, Blinky
Dec 2 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
6
by: sakms | last post by:
I am attempting to validate radio buttons in Netscape with JavaScript. Everything works excellent in Explorer, but refuses to work in Netscape (all versions). =========== JAVASCRIPT CODE...
12
by: Claire Lescarret | last post by:
Hello, I have devoted my time to write valid html 4.01 strict, and CSS-1 and 2 *but* I also have to use third party's code for webcounter (StatCounter) and Google's SiteSearch, which are...
5
by: Leszek | last post by:
Hi I've got html form and i want to validate it using javascript I have somerthing like this: <p> <b>Gender: <font color="red">*</font></b> <input type="radio" value="Male"...
6
by: Advo | last post by:
Hi there. Having a few issues and cannot see a way to actually do the following. ive duplicated a simple questionnaire as shown here: http://www.hackeradio.com/questionnaire.html meaning...
1
by: Suma | last post by:
Hi, i have a problem with the controls .i have to validate Form1 Radio button option is checked or Not in the Form2. even after checking the radio button also in FOrm2 it is always taking as...
2
by: SONIQ | last post by:
Using javascripts to validate this form. Basic operation, when a user clicks the submit order button, the javascript code must validate everything entered by the user. Please help finnish this...
2
by: forbes | last post by:
Hi, I have a form that contains multiple groups of checkboxes that act like radio buttons (at the clients insistance). There is one text field that is required and 28 checkbox groups. Here an...
5
by: satyabhaskar | last post by:
hi all, In my web page i have created radio buttons dynamically on to the page .....following is my code string Course, Semester, Section; int rowsCount; string con =...
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
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?
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...
0
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
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,...

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.