PDA

View Full Version : Radio button validation


Geoserv
01-11-2006, 10:39 PM
How do you validate this on form submit:

<strong>What type of Ad are you interested in?</strong>(Required)<p>

<input TYPE="radio" NAME="adtype" VALUE="reg">Regular<br>
<input TYPE="radio" NAME="adtype" VALUE="fly">Fly-out<br>
<input TYPE="radio" NAME="adtype" VALUE="custom">Custom<br>
<p>


I have the form validating the input text fields but not sure how to do radio buttons.

This is what I use for the text fields:

in the head:

<SCRIPT>
function validate(){
var el = document.getElementsByTagName('*');
var ret = true;
for(var i=0;i<el.length;i++){
if(el[i].getAttribute('req')!=null){
el[i].style.borderWidth = 0;
el[i].style.borderColor = "black";
if(el[i].value.length<1){
el[i].style.borderWidth = 4;
el[i].style.borderColor = "orange";
ret = false;
} }
}
if(!ret){
alert("Some required fields have not been filled in, they are marked in orange.");
}
return ret;
}
</SCRIPT>


and in the body:

<form action="/cgi/formmail" method="post" name="ad" onsubmit="return validate();">

<input type="hidden" name="recipient" value="ad@apnaonline.ca">

<strong>Name</strong>(Required)<br>
<input name="name" TYPE=text SIZE="30" MAXLENGTH="30" req="name"><p>

<strong>E-Mail</strong>(Required)<br>
<input name="email" TYPE=text SIZE="30" MAXLENGTH="30" req="email"><p>

<strong>Address</strong><br>
<input name="Address" TYPE=text SIZE="30" MAXLENGTH="30"><p>


etc...then it gets into radio buttons to be selected.

Thanks
Geoserv.