Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Help with required fields Javascript

Reply
Thread Tools

Help with required fields Javascript

 
 
Cliff R.
Guest
Posts: n/a
 
      08-13-2004
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[i];
if (tempobj.name.substring(0,=="required") {
if (((tempobj.type=="text"||tempobj.type=="textarea") &&
tempobj.value=='')||(tempobj.type.toString().charA t(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
}
}
}
}
if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUppe rCase();
alert("Please make sure the "+shortFieldName+" field was properly
completed.");
return false;
}
else
return true;
}
// End -->
</SCRIPT>
 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      08-13-2004
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.

 
Reply With Quote
 
 
 
 
Cliff R.
Guest
Posts: n/a
 
      08-14-2004
Thank you so much for your help!

Cliff




On 13 Aug 2004 14:46:21 -0700, Lee <(E-Mail Removed)> wrote:

>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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
epydoc: How to add new fields as the building fields? Cyril.Liu Python 0 12-02-2008 05:01 AM
print struct fields and its member structs' fields recursively, generically call_me_anything C++ 4 09-30-2007 10:12 PM
how to copy from fields to other fields middletree ASP General 1 11-05-2003 06:24 PM
Help: Make all fields in table tag required. Spanky Javascript 1 09-08-2003 08:38 AM
Netscape hidden fields - array - multiple fields with same name mark.reichman@rl.af.mil Javascript 0 07-17-2003 03:05 PM



Advertisments