/    Sign up×
Community /Pin to ProfileBookmark

onsubmit form verification problems with radio buttons

I set up a simple data checking utility in js to check a form before it’s uploaded, using the onsubmit event in the <form> tag. It worked fine in the text boxes but when it came to the radio buttons, it wouldn’t work at all. All I wanted to check is to see if one of the radio buttons was selected using a line like if(document.inputform.VehicleType.value ==”) and it simply wouldn’t pick up an unselected radio button group. I tried the oppossite like if(!(….1value!=”&&….2value!=”&&……..)) to see if that would trap the one but no way either. Does anyone have a suggestion!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 27.2004 — to verify wether a checkbox or a radio button is checked or not use the [b]checked[/t] attribute, which returns boolean true/false values (true is default).



On the other hand, if the radio buttons have all the same name, you have to verify by their order number, which one of them is checked. (be cause in this case the refenece by name is in fact an array of subelemets)



[code=php]
document.inputform.VehicleType = f;
for(var i=0;i<f.length;i++){
if(f[i].checked){
...do someth
}
else{
...do another
}
}
[/code]
×

Success!

Help @jakester 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...