Help with required fields Javascript

Discussion in 'Javascript' started by Cliff R., Aug 13, 2004.

  1. Cliff R.

    Cliff R. Guest

    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>
     
    Cliff R., Aug 13, 2004
    #1
    1. Advertising

  2. Cliff R.

    Lee Guest

    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.
     
    Lee, Aug 13, 2004
    #2
    1. Advertising

  3. Cliff R.

    Cliff R. Guest

    Thank you so much for your help!

    Cliff




    On 13 Aug 2004 14:46:21 -0700, Lee <> 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.
     
    Cliff R., Aug 14, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Allen

    Re: Required fields disabled

    Scott Allen, Jul 20, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    478
    Scott Allen
    Jul 20, 2004
  2. Tien
    Replies:
    1
    Views:
    470
    Martin Dechev
    Oct 22, 2004
  3. Just D.
    Replies:
    0
    Views:
    464
    Just D.
    Mar 10, 2006
  4. =?Utf-8?B?RGF2ZQ==?=
    Replies:
    1
    Views:
    916
    S. Justin Gengo
    Jun 5, 2006
  5. Spanky
    Replies:
    1
    Views:
    130
    lallous
    Sep 8, 2003
Loading...

Share This Page