/    Sign up×
Community /Pin to ProfileBookmark

Need Radio Button Check Code

I need the following code to check if I haven’t checked a certain radio button.

Thanks

[CODE]<form action=”inputque.php” method=”post”>
<body>
<p>Question:</p>
<p>
<label>
<input name=”ques” type=”text” size=”75″ />
</label>
</p>
<p>&nbsp;</p>
<p>A:</p>
<p>
<input name=”a” type=”text” size=”75″ />
<label>
<input type=”radio” name=”select” value=”1″ /> <br />
<br />
</label>
</p>
<p>B:</p>
<p>
<input name=”b” type=”text” size=”75″ />
<input type=”radio” name=”select” value=”2″ /> <br />
</p>
<p>C:</p>
<p>
<input name=”c” type=”text” size=”75″ />
<input type=”radio” name=”select” value=”3″ /> <br />
</p>
<p>D:</p>
<p>
<input name=”d” type=”text” size=”75″ />
<input type=”radio” name=”select” value=”4″ /> <br />
</p>
<pre> <input type=”submit” name=”Submit” value=”Next” />

</pre>
</body>
</form>[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERJul 16.2009 — Try one of the following or its variation:
<i>
</i>// RBtn.js

function getRBtnID(ids) {
var obj = document.getElementById(ids);
// next line is collects information about options
var sel = document.getElementsByName(obj.name);
var fnd = -1;
var str = '';
for (var i=0; i&lt;sel.length; i++) {
if (sel[i].checked == true) { str = sel[i].value; fnd = i; }
}
// return fnd; // return option index of selection
// comment out next line if option index used in line above <br/>
return str;
}

/* Optional use in program */
function getRBtnName(GrpName) {
var sel = document.getElementsByName(GrpName);
var fnd = -1;
var str = '';
for (var i=0; i&lt;sel.length; i++) {
if (sel[i].checked == true) { str = sel[i].value; fnd = i; }
}
// return fnd; // return option index of selection
// comment out next line if option index used in line above <br/>
return str;
}

I suspect you want to use the "getRBtnName('select')" function.

Modify it according to the comments to return either the value or the index or default.

Note: I would change the 'name=select' of your script because it might be confused

with the <select ...> tag. Perhaps you should use 'name="RBtnSelect" instead (?)

Search this forum for other alternative radio status checks.

?
×

Success!

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