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.
ABVFP Check Box
Collapse
X
-
Re: ABVFP Check Box
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>
<script>
//change two names below to your form's names
document.forms.Form1.agree.checked=false
</script>
onClick="agreesubmit(this)"
disabled
This script is presented at http://www.dynamicdrive.com/dynamici...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.htmlNavaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!
-
Comment