Click to See Complete Forum and Search --> : only the first radio button of four validates?


peter butler
01-06-2004, 11:42 AM
only the first radio button validates. when you select the second radio button, the form bypasses the validation and i cant see why?



<html>
<head>

<script type="text/javascript">

function radioCheck(elm)

button has been selected
{
var checked = document.forms["registration"].elements[""];

element and created a variable
var count;

//new variable called count
for (count=0; count<4; count++)

//a loop to check the status of all radio buttons.
{

//the loop starts at 0 then increments by 1 each time
if (elm[count].checked)
return true;

//if a radio has been checked the function returns true
else return false;

//if no radio checked the function returns false
}
}



function isReady (form)
{

if(radioCheck(form.title)==false)
{


alert("Please give us your title")
return false;
}

else return true;
}

</script>
</head>
<body>

<form id="signInForm" method="post" onsubmit="return isReady(this)" name="registration" action="#">

<input id="titleMr" name="title" type="radio">
<input id="titleMrs" name="title" type="radio">
<input id="titleMiss" name="title" type="radio">
<input id="titleMs" name="title" type="radio">

<input id="reset" type="reset" value="reset">
<input id="next" type="submit" value="Next">

</body>
</html>

Pittimann
01-06-2004, 12:00 PM
Hi!

You have your return true and false inside the loop!
Please try something like:

<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
var checkRadio=0;
function radioCheck(elm) {
var checked = document.forms["registration"].elements[""];
var count;
for (count=0; count<4; count++) {
if (document.registration.title[count].checked==true)
checkRadio=1;
}
if (checkRadio!=0)
return true;
else return false;
}
function isReady (form) {
if(radioCheck(form.title)==false) {
alert("Please give us your title")
return false;
}
else return true;
}
//-->
</script>
</head>
<body>
<form id="signInForm" method="post" onsubmit="return isReady(this)" name="registration" action="#">
<input id="titleMr" name="title" type="radio">
<input id="titleMrs" name="title" type="radio">
<input id="titleMiss" name="title" type="radio">
<input id="titleMs" name="title" type="radio">
<input id="reset" type="reset" value="reset">
<input id="next" type="submit" value="Next">
</form>
</body>
</html>

Cheers - Pit