Hello, I have a form that has a few required fields and also an "agree
to terms" checkbox that must be required. I have used Javascripts for
both functions individually, but I need a little help in combining
them. Can someone help me combine these two scripts so they both work
on the same page, with <FORM METHOD=POST onSubmit="retur n
checkrequired(t his)" etc., checking for required fields and making
sure the agree-to-terms button is checked? Thank you!
<script language="JavaS cript" type="text/JavaScript">
<!--//hide script
function checkme() {
missinginfo = "";
if (!document.form .agree.checked) {
missinginfo += "\n - You must agree to the terms";
}
if (missinginfo != "") {
missinginfo ="You must click the box that indicates you agree.";
alert(missingin fo);
return false;
}
else {
return true;
}
}
// --->
</script>
<SCRIPT TYPE="text/JavaScript">
<!-- Begin
function checkrequired(w hich) {
var pass=true;
if (document.image s) {
for (i=0;i<which.le ngth;i++) {
var tempobj=which.e lements[i];
if (tempobj.name.s ubstring(0,8)== "required") {
if (((tempobj.type =="text"||tempo bj.type=="texta rea")&&
tempobj.value== '')||(tempobj.t ype.toString(). charAt(0)=="s"& &
tempobj.selecte dIndex==0)) {
pass=false;
break;
}
}
}
}
if (!pass) {
shortFieldName= tempobj.name.su bstring(8,30).t oUpperCase();
alert("Please make sure the "+shortFieldNam e+" field was properly
completed.");
return false;
}
else
return true;
}
// End -->
</SCRIPT>
to terms" checkbox that must be required. I have used Javascripts for
both functions individually, but I need a little help in combining
them. Can someone help me combine these two scripts so they both work
on the same page, with <FORM METHOD=POST onSubmit="retur n
checkrequired(t his)" etc., checking for required fields and making
sure the agree-to-terms button is checked? Thank you!
<script language="JavaS cript" type="text/JavaScript">
<!--//hide script
function checkme() {
missinginfo = "";
if (!document.form .agree.checked) {
missinginfo += "\n - You must agree to the terms";
}
if (missinginfo != "") {
missinginfo ="You must click the box that indicates you agree.";
alert(missingin fo);
return false;
}
else {
return true;
}
}
// --->
</script>
<SCRIPT TYPE="text/JavaScript">
<!-- Begin
function checkrequired(w hich) {
var pass=true;
if (document.image s) {
for (i=0;i<which.le ngth;i++) {
var tempobj=which.e lements[i];
if (tempobj.name.s ubstring(0,8)== "required") {
if (((tempobj.type =="text"||tempo bj.type=="texta rea")&&
tempobj.value== '')||(tempobj.t ype.toString(). charAt(0)=="s"& &
tempobj.selecte dIndex==0)) {
pass=false;
break;
}
}
}
}
if (!pass) {
shortFieldName= tempobj.name.su bstring(8,30).t oUpperCase();
alert("Please make sure the "+shortFieldNam e+" field was properly
completed.");
return false;
}
else
return true;
}
// End -->
</SCRIPT>
Comment