Help with required fields Javascript

C

Cliff R.

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="return
checkrequired(this)" etc., checking for required fields and making
sure the agree-to-terms button is checked? Thank you!

<script language="JavaScript" 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(missinginfo);
return false;
}
else {
return true;
}
}
// --->
</script>


<SCRIPT TYPE="text/JavaScript">
<!-- Begin
function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements;
if (tempobj.name.substring(0,8)=="required") {
if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
}
}
}
}
if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();
alert("Please make sure the "+shortFieldName+" field was properly
completed.");
return false;
}
else
return true;
}
// End -->
</SCRIPT>
 
L

Lee

Cliff R. said:
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="return
checkrequired(this)" etc., checking for required fields and making
sure the agree-to-terms button is checked? Thank you!

Change the final "return true" in checkrequired() to "return checkme()".
Indentation would make your code much easier to read.
 
C

Cliff R.

Thank you so much for your help!

Cliff




Cliff R. said:

Change the final "return true" in checkrequired() to "return checkme()".
Indentation would make your code much easier to read.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top