ll a écrit :
<script type="text/javascript">
function checkform( f ) // f is the form to check
{
var txt1 = 'Please make a selection for the Learning Outcome :',
txt2 = '\nYour favorite Ice Cream flavor is a required field.'+
'\nPlease try again.'
var L = f.length+1;
for( var i=1; i<L; i++) // for each element of the form
{
if(f[i].type == 'radio' && // if it is a radio-button and
f[i].name.indexOf(' Out')>=0) // its name contents 'Out'
{
var OK = false;
var r = f[i].elements['Out' + i + 'a']; // radios collection #i
for( var j=0; j<r.length; i++) // for each radio of them
if(r[j].checked) OK = true; // is there one checked ?
if(!OK) { // if not :
alert(txt1 + r[i].name +txt2); // alert
r[0].focus(); // go to it
return false; // stop to submit
}
}
}
return true; // if Oll is Korrect send 'true'
}
</script>
<form onsubmit="retur n checkform(this) ;" blah >
--
sm
Hi,
I have a radio button question. I have about 20 sets (20 questions,
each with a set of 4 radio buttons) and would like to loop through
them in doing a form validation.
I have a radio button question. I have about 20 sets (20 questions,
each with a set of 4 radio buttons) and would like to loop through
them in doing a form validation.
<script type="text/javascript">
function checkform( f ) // f is the form to check
{
var txt1 = 'Please make a selection for the Learning Outcome :',
txt2 = '\nYour favorite Ice Cream flavor is a required field.'+
'\nPlease try again.'
var L = f.length+1;
for( var i=1; i<L; i++) // for each element of the form
{
if(f[i].type == 'radio' && // if it is a radio-button and
f[i].name.indexOf(' Out')>=0) // its name contents 'Out'
{
var OK = false;
var r = f[i].elements['Out' + i + 'a']; // radios collection #i
for( var j=0; j<r.length; i++) // for each radio of them
if(r[j].checked) OK = true; // is there one checked ?
if(!OK) { // if not :
alert(txt1 + r[i].name +txt2); // alert
r[0].focus(); // go to it
return false; // stop to submit
}
}
}
return true; // if Oll is Korrect send 'true'
}
</script>
<form onsubmit="retur n checkform(this) ;" blah >
--
sm
Comment