Thursday, February 28, 2008

javascript 中 radio button 的判断

HTML 页面;

<(form method="post" action="https://××××××××" name="application">
<(input value="M" name="gender" type="radio">Male
<(input value="F" name="gender" type="radio">Female

<(input name="submit" value="Submit" onclick="return validator(application)"type="submit")>

JAVASCRIPT 中
function validator(theForm)
{
if (!theForm.gender[0].checked &&!theForm.gender[1].checked)
{ alert("Select your gender, please!");theForm.gender[0].focus();return false; }


最主要的radio button 是采用数组形式存储的。