View Full Version : [RESOLVED] radio array buttons checking
scoutt
10-19-2007, 12:44 PM
I am using this code from coot, thanks coot,
http://www.htmlforums.com/showpost.php?p=405109&postcount=2
but I think it won't work for my situation. See it does work for the most part but I have to deal with arrays, meaning I do this
<input type="radio" name="approve_[7]" value="7">
where 7 can be any number. How do I check arrays?
¥åßßå
10-19-2007, 02:01 PM
I'm a tad lost to what your problem is? From a quick look at that code, and your code snippet, then it should handle your arrays.
The only bit that I can see that you may want to change is this bit radQ'+(i+1) which would become '+rads[i].name ?
Any chance of a sample page and what you expect to happen?
¥
scoutt
10-19-2007, 02:08 PM
Well I have changed it slightly to not use radQ'+(i+1) at all.
function Check(){
var rads=document.getElementsByTagName('input');
for(i=0;i<rads.length;i++) {
if((rads[i].type=='radio')&&(rads[i].checked==false)) {
alert('Please approve or decline something before you submit the form.');
return false;
}
}
}
I cannot show the code as it is not online yet. but imagine this in the form
<input type="radio" name="approve_[7]" value="7">
<input type="radio" name="approve_[7]" value="delete">
<input type="radio" name="approve_[7]" value="deny">
How do I check for at least one of those to be checked. If none click the code works great, if you click one it still tells you that none are checked. does that help?
coothead
10-19-2007, 03:54 PM
Hi there Brian,
I have just returned home to find you in distress. :crying:
Let's hope that this modification gets you up and running again. :agree:
<script type="text/javascript">
function radioCheck() {
var count=0;
var rads=document.getElementsByTagName('input');
for(i=0;i<rads.length;i++) {
if((rads[i].type=='radio')&&(rads[i].checked==true)) {
count++;
}
}
if(count==0) {
alert('Please approve or decline something before you submit the form');
return false;
}
else {
count=0;
return true;
}
}
</script>
<form action="#" onsubmit="return radioCheck()">
<input type="radio" name="approve_[7]" value="7">
<input type="radio" name="approve_[7]" value="delete">
<input type="radio" name="approve_[7]" value="deny">
<input type="submit">
</form>
scoutt
10-19-2007, 06:05 PM
Bravo old man, you pull through again. Thanks. works a charm
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.