/    Sign up×
Community /Pin to ProfileBookmark

Radio button checked?

Hi,

I have a radio button that contains 2 options. I want to do a simple validation check to test if it’s been seleted. I having a problem doing this, so I put an alert in to see that the state of checked equals. but when I execute this I get ‘Undefined’. Can someone please have a look.

<INPUT TYPE=radio NAME=”electronic” VALUE=”Electronic” CHECKED>Electronic<BR>
<INPUT TYPE=radio NAME=”electronic” VALUE=”Paper”>Paper</TD>

alert(“”+frm.electronic.checked);
if (frm.electronic.checked == false)
{

alert(“Please select if the document you are attaching is electronic or on paper.”);
frm.electronic.focus();
submitOK=”False”;

}

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@CharlesJun 07.2005 — Your radio buttons will be grouped into an Array that you have to step through.&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta name="Content-Script-Type" content="text/javascript"&gt;
&lt;meta name="Content-Style-Type" content="text/css"&gt;
&lt;title&gt;Example&lt;/title&gt;

&lt;script type="text/javascript"&gt;
&lt;!--
function check (f) {
var checked = false, e, i = 0;
while (e = f.elements['foo-bar'][i++]) {if (e.checked) checked = true};
if (!checked) {
alert ('Please select either a "Foo" or a "Bar".');
return false;
}
}
// --&gt;
&lt;/script&gt;

&lt;style type="text/css"&gt;
&lt;!--
fieldset {padding:1ex; width:7em}
label {display:block; text-align:left}
button {display:block; margin:1ex auto}
--&gt;
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;form action="some-script.pl" onsubmit="return check (this)"&gt;
&lt;fieldset&gt;
&lt;legend&gt;Example&lt;/legend&gt;
&lt;label&gt;&lt;input type="radio" name="foo-bar"&gt;Foo&lt;/label&gt;
&lt;label&gt;&lt;input type="radio" name="foo-bar"&gt;Bar&lt;/label&gt;
&lt;button type="submit"&gt;Submit&lt;/button&gt;
&lt;/fieldset&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @A05087 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,
)...