PDA

View Full Version : ABVFP Check Box



greyhame
06-29-2007, 11:04 PM
Can someone tell me how I can validate whether a checkbox is checked when a form is submitted. I have a form for users to sign up for a newsletter. Users must agree to a statement in the form by checking the box. I would like to be able to reject the form if it is unchecked. Thanks.

navaldesign
06-30-2007, 06:47 AM
This is usually done using Javascript, before the form info is even submitted. Here is my preferred method. I use it because it will not get in conflict with BV's own form fields validation, so you can use both in the same form.

We will suppose that you are using a standard BV form, named Form1. If the name is different, change the part in RED to be the same as the form name. We will also suppose that the checkbox is named "agree". If not, change the part in BLUE to be the same as the checkbox name:

Step 1. Paste the following code in the "Between head Tag" of your page html:



<script>
//"Accept terms" form submission- By Dynamic Drive
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use
var checkobj
function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){ //hunt down submit button
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
}
}
}
function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("Please read/accept terms to submit form")
return false
}
}
}
</script>


Step 2. Right Click on the form, select HTML, and paste the following code in the AFTER TAG of the form html:



<script>
//change two names below to your form's names
document.forms.Form1.agree.checked=false
</script>


Step 3. Right Click on the checkbox, select HTML, and paste the following code in the INSIDE TAG of the checkbox HTML:



onClick="agreesubmit(this)"


Step 4. Right click on your Submit button, select HTML, and paste the following code in the Inside Tag of the Submit button HTML:



disabled


That's all.

This script is presented at http://www.dynamicdrive.com/dynamicindex16/acceptterm.htm

I just show here how to use it with a BV form.

To see it working, visit http://www.dbtechnosystems.com/Tips/Agree_to_Terms.html

greyhame
07-08-2007, 12:04 PM
Greatly appreciated! This disables the submit button until the agree box is checked.