Click to See Complete Forum and Search --> : form validation to a new page


dennic
02-06-2003, 06:17 PM
Hi

No javascript expert here so just wondering if i could get some help of someone please.

im using a form to for an agreement page where the user either agrees or they disagree, if they disagree i simply want a message to say that there application can't be continued. however if they tick agree i want it to go to the next page.

at the moment it just goes to the next page no matter what you tick.

here is the code. any help would be appreciated!!


<SCRIPT LANGUAGE="javascript">
<!--
function check() {
g=document.declaration;
if(g.disagree.checked==true && g.agree.checked==true){
alert("You cant tick both boxes!");
} else if(g.disagree.checked==true){
alert("You can't proceed");
} else if(g.agree.checked==true) {
alert("You may proceed!");
} else {
alert("You havent ticked a box!")
}
}

//-->
</SCRIPT>

<!--Start of declaration form-->

<form name="declaration" action="applications.html">

<center>
<input type="checkbox" id="disagree" value="declaration" />Disagree
<input type="checkbox" id="agree" value="declaration" />I agree

</center>

<br>
<br>

<a href="applications.html" onClick="return check()">
<center><input type="submit" value="Begin" name="applications" align="right" >

</center>

</a>

</form>

Dan Drillich
02-06-2003, 08:09 PM
Please try -


<SCRIPT LANGUAGE="javascript">
<!--
function check() {
g=document.declaration;
if(g.disagree.checked==true && g.agree.checked==true){
alert("You cant tick both boxes!");
return false;
} else if(g.disagree.checked==true){
alert("You can't proceed");
return false;
} else if(g.agree.checked==true) {
alert("You may proceed!");
return true;
} else {
alert("You havent ticked a box!");
return false;
}
}

//-->
</SCRIPT>

<!--Start of declaration form-->

<form name="declaration" action="applications.html" onsubmit="return check();">

<center>
<input type="checkbox" id="disagree" value="declaration" />Disagree
<input type="checkbox" id="agree" value="declaration" />I agree

</center>

<br>
<br>


<center>
<input type="submit" value="Begin" name="applications" align="right" >
</center>



</form>



Cheers,
Dan