...

View Full Version : Need help in authorising form elements



Twisties34
06-25-2009, 02:34 PM
Hi, just wondering if someone can help me with a small problem. I have a form on my website that I want to confirm the user has ticked all the boxes before clicking on the Submit button. The submit button must then load another web page.

I did find a tutorial on Java Script Kit, but haven't completely worked out how to apply it to my page. Code is as follows



<script type="text/javascript">
<!--
function validate(){
if ((document.agree.chk_18.value=="")||
(document.agree.chk_police.value=="")||
(document.agree.chk_damages.value=="")||
(document.agree.chk_agree.value=="")){
.alert ("You must fill in all of the required .fields!")
.return false
.}
else
return true
}
//-->
</script>


As I want the boxes to be ticked, is this script checking that they are unticked? Should I have a space between the double quotes? And how do I get the Submit button named btn_agree to load the next page? ATM the button is loading the page before the check is taking place.

Form Code:


<form name="agree" id="agree" method="post" action="x-rated3.htm" onsubmit="return validate()">
<table width="85%" border="0">
<tr>
<td><input name="chk_18" type="checkbox" id="chk_18" value="checkbox" /></td>
<td>I am over 18 or legal age in my jurisdiction to view or access adult material. </td>
</tr>
<tr>
<td><input name="chk_police" type="checkbox" id="chk_police" value="checkbox" /></td>
<td>I am not a member of the police force in any state or nationality.</td>
</tr>
<tr>
<td><input name="chk_damages" type="checkbox" id="chk_damages" value="checkbox" /></td>
<td>I do not hold the owner of this website liable for any damages whatsoever in accessing the material on this site. </td>
</tr>
<tr>
<td><input name="chk_agree" type="checkbox" id="chk_agree" value="checkbox" /></td>
<td>I have read and agree with all the above. </td>
</tr>
<tr>
<td><input name="btn_agree" type="submit" id="btn_agree" value="Agree" /></td>
<td>&nbsp;</td>
</tr>
</table>
</form>

abduraooft
06-25-2009, 02:57 PM
Try

<script type="text/javascript">

function validate(){
if (document.agree.checked==false ||
document.agree.chk_police.checked==false||
document.agree.chk_damages.checked==false||
document.agree.chk_agree.checked==false){
alert ("You must fill in all of the required .fields!")
return false;
}
else
return true;
}

</script>

Twisties34
06-25-2009, 03:02 PM
Beautiful. Works perfectly now. Thankyou :D

*huggles*



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum