By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,435 Members | 2,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,435 IT Pros & Developers. It's quick & easy.

Validating radio

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.