/    Sign up×
Community /Pin to ProfileBookmark

radio button validation

I have an mysql array with several radio buttons,

<INPUT name=”bookout” id=”bookout” type=”radio” class=”formslova” value=’value1′>
<INPUT name=”bookout” id=”bookout” type=”radio” class=”formslova” value=’value2′>
<INPUT name=”bookout” id=”bookout” type=”radio” class=”formslova” value=’value3′>

I want to make a button validation:

if (document.getElementById(“bookout”).checked==false) {
alert(‘error’);

For some reason when I have more that one button in the array only the first counts, meaning only when first is clicked is the button validation checked=true.

to post a comment
Java

3 Comments(s)

Copy linkTweet thisAlerts:
@TchiboauthorMay 18.2011 — I am sorry, wrong forum.
Copy linkTweet thisAlerts:
@nyshangalMay 19.2011 — all your radio button has same id, which is incorrect, that is why your validation fails.

you have to change the id for your radio button and that should work
Copy linkTweet thisAlerts:
@svidgenMay 19.2011 — Yup -- change or remove the ID on the buttons. It'll probably easiest to validate using a reference to the form:

[code=html]var form = document.getElementById('form_id');
if (!form.radio_group_name) {
// alert the user somehow
}[/code]


... or something along those lines. And remember that client-side validation is not sufficient in itself! Check everything server-side as well.
×

Success!

Help @Tchibo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...