I have a simple javascript command for checking form elements, this command is nested within PHP. Basically when the form is submitted I need to check each of the elements has a value selected.
I can get this to work for text boxes and drop down lists as shown in the code below.
Code: Select all
function validate()
{
if(document.form1.username.value.length <1)
{
alert ("Please enter a value for Username");
document.form1.username.focus();
return false;
}
return true;
}I am trying to achieve this for a two radio button selection set
the name of the each radiobutton is
gender
button 1's value is Male
button 2's value is female.
How would I go about using my cheking function on radio buttons
here is the code for my button
Code: Select all
<td width="12%" class="lefttopbottom"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"> Gender</font></td>
<td width="8%" class="bottomtop"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Male
<input type="radio" name="gender" value="Male">
</font></td>
<td width="13%" class="bottomtop"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Female
<input type="radio" name="gender" value="Female">
</font></td>Code: Select all
function validate()
{
if(document.form1.gender.value == "")
{
alert ("Please enter a value for Gender");
//document.form1.username.focus();
return false;
}
return true;
}Can anyone help please.
Many Thanks
Jamie