Pothh Member
![Member Member](https://2img.net/h/i654.photobucket.com/albums/uu265/hoover78/User%20ranks/member.png)
![Pothh](https://2img.net/h/i654.photobucket.com/albums/uu265/hoover78/jay.gif)
Posts : 7 Join date : 2011-06-05
![form validation of a checkbox not quite right Empty](https://2img.net/i/fa/empty.gif) | Subject: form validation of a checkbox not quite right Fri Jun 17, 2011 2:03 am | |
| confused. my validation of the clicking on a checkbox doesn't seem to send the value with the form. Should I be adding value='whatever' in the xhtml? - Code:
-
<form method="post" id='myForm' name='myForm' onsubmit="return checkform(this)" action="/cgi-bin/script/520/9/98"> <script type='text/javascript'> //<![CDATA[
function checkform(form) { //validate the terms checkbox if (!document.myForm.acceptance.checked) { // ! means "not" document.getElementById("trmserr").innerHTML = "You must accept the terms and conditions"; document.getElementById("myForm").acceptance.value = ""; // clear the field setTimeout("document.getElementById('myForm').acceptance.focus()", 25); // refocus on it return false; } else { document.getElementById("trmserr").innerHTML = ""; } return true; }
<span id="trmserr" class='formErrorWarning'></span> <p> <a class='tooltip' href='#'> <span class='compulsory'>*</span> <span class='the_tip'>This is required because, by proceeding, you are accepting these terms and conditions for this purchase. They will be emailed to you along with your order confirmation.</span></a> <input type="checkbox" id='acceptance' name="acceptance" /> I have read and I accept the terms and conditions.</p>
It works if JS is disabled and it works only sometimes when it is enabled. |
|
BaconBitz Member
![Member Member](https://2img.net/h/i654.photobucket.com/albums/uu265/hoover78/User%20ranks/member.png)
![BaconBitz](https://2img.net/u/1111/11/56/92/avatars/184-32.jpg)
Posts : 4 Join date : 2011-05-11
![form validation of a checkbox not quite right Empty](https://2img.net/i/fa/empty.gif) | Subject: Re: form validation of a checkbox not quite right Fri Jun 17, 2011 2:04 am | |
| you've got syntax errors in that code. |
|
Pothh Member
![Member Member](https://2img.net/h/i654.photobucket.com/albums/uu265/hoover78/User%20ranks/member.png)
![Pothh](https://2img.net/h/i654.photobucket.com/albums/uu265/hoover78/jay.gif)
Posts : 7 Join date : 2011-06-05
![form validation of a checkbox not quite right Empty](https://2img.net/i/fa/empty.gif) | Subject: Re: form validation of a checkbox not quite right Fri Jun 17, 2011 2:06 am | |
| must be a copy and paste thing coz they aren't showing in the error console of FF
it seems to be working now with two lines removed. (thanks lt). |
|
Sponsored content
![form validation of a checkbox not quite right Empty](https://2img.net/i/fa/empty.gif) | Subject: Re: form validation of a checkbox not quite right ![form validation of a checkbox not quite right Empty](https://2img.net/i/empty.gif) | |
| |
|