Help with required fields Javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cliff R.

    #1

    Help with required fields Javascript

    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>
  • Lee

    #2
    Re: Help with required fields Javascript

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

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

    Comment

    • Cliff R.

      #3
      Re: Help with required fields Javascript

      Thank you so much for your help!

      Cliff




      On 13 Aug 2004 14:46:21 -0700, Lee <REM0VElbspamtr ap@cox.net> wrote:
      [color=blue]
      >Cliff R. said:[color=green]
      >>
      >>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 (this)" etc., checking for required fields and making
      >>sure the agree-to-terms button is checked? Thank you![/color]
      >
      >Change the final "return true" in checkrequired() to "return checkme()".
      >Indentation would make your code much easier to read.[/color]

      Comment

      Working...