SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast pjdowson's Avatar
    Join Date
    May 2004
    Location
    Clinton, IA
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form Validation (FormCheck.js)

    Hi,

    I am using a validation script written by Netscape to validate name, phone, cc etc... information. The form validates OK, but whether it validates good or bad, it still submits the form either way. I am sure I am missing something, but its been a long day and I cannot see what, why or where.

    The script may be old, but the validation part works great, I just cant get it to not submit.

    TIA

    ---> See Below <---

    The formchek script I am using can be taken from here:

    http://developer.netscape.com/docs/e...al/FormChek.js

    The overall homepage for the script is here:

    http://developer.netscape.com/docs/e.../overview.html

    My HTML I am using to call the script is:

    Code:
    <HTML>
    <HEAD>
    <SCRIPT LANGUAGE="JavaScript1.1" SRC="FormChek.js"></SCRIPT>
    
    <SCRIPT>
    function validateUSPersonalInfo(form)
    {   return (
          checkString(form.elements["LastName"],sUSLastName) &&
          checkString(form.elements["FirstName"],sUSFirstName) &&
          checkString(form.elements["StreetAddress"],sUSAddress) &&
          checkString(form.elements["City"],sCity) &&
          checkStateCode(form.elements["State"]) &&
          checkZIPCode(form.elements["ZIP"]) &&
          checkUSPhone(form.elements["Phone"]) &&
          checkEmail(form.elements["Email"]) &&
          checkCreditCard (form.elements["CreditCardType"], form.elements["CreditCardNumber"]) &&
          checkDate(form.elements["ExpirationYear"], form.elements["ExpirationMonth"], form.elements["ExpirationDay"], sExpirationDate, true)
        )
    }
    
    function displayUSPersonalInfo(form)
    {     var outputTable = "<HTML><HEAD><TITLE>Results</TITLE></HEAD><BODY><H1>Data Entered:</H1><TABLE BORDER=1>" +
          "<P>Normally, the data would be mailed or submitted to a server, but since this is just a demo, we replace the usual Submit button with a mockup that just calls some code to display what was typed in.</P>" + 
          "<TR><TD>" + sUSLastName + "</TD><TD>" + form.elements["LastName"].value + "</TD></TR>" +
          "<TR><TD>" + sUSFirstName + "</TD><TD>" + form.elements["FirstName"].value + "</TD></TR>" +
          "<TR><TD>" + sUSAddress + "</TD><TD>" + form.elements["StreetAddress"].value + "</TD></TR>" +
          "<TR><TD>" + sCity + "</TD><TD>" + form.elements["City"].value + "</TD></TR>" +
          "<TR><TD>" + sStateCode + "</TD><TD>" + form.elements["State"].value + "</TD></TR>" +
          "<TR><TD>" + sZIPCode + "</TD><TD>" + form.elements["ZIP"].value + "</TD></TR>" +
          "<TR><TD>" + sPhone + "</TD><TD>" + form.elements["Phone"].value + "</TD></TR>" +
          "<TR><TD>" + sEmail + "</TD><TD>" + form.elements["Email"].value + "</TD></TR>" +
          "<TR><TD>" + sCreditCardNumber + "</TD><TD>" + form.elements["CreditCardNumber"].value + "</TD></TR>" +
          "<TR><TD>" + sExpirationDate + "</TD><TD>" + form.elements["ExpirationYear"].value + "/" + form.elements["ExpirationMonth"].value + "/" + form.elements["ExpirationDay"].value + "</TD></TR>" +
          "<TR><TD>" + sOtherInfo + "</TD><TD>" + form.elements["OtherInfo"].value + "</TD></TR>" +
          "</TABLE></BODY></HTML>"
          document.writeln(outputTable)
          document.close()
          return true
    }
    
    
    </SCRIPT>
    
    </HEAD>
    
    <BODY BGCOLOR="#ffffff">
    <P><I>Fields marked with an asterisk (*) must be entered.</I>
    <FORM NAME="PersonalInfo" action="bogus.asp" method="GET">
    
    <table bgcolor='#CCCCCC' align="center" width="330" cellspacing="1" cellpadding="3" border="0">
    <TR>
        <TD bgcolor="#EEEEEE">* Last Name:</TD>
        <TD bgcolor="#EEEEEE"><INPUT TYPE="text" NAME="LastName" onFocus="promptEntry(sUSLastName)" onChange="checkString(this,sUSLastName)"></TD>
    </TR>
    <TR>
        <TD bgcolor="#EEEEEE">* First Name:</TD>
        <TD bgcolor="#EEEEEE"><INPUT TYPE="text" NAME="FirstName" onFocus="promptEntry(sUSFirstName)" onChange="checkString(this,sUSFirstName)"></TD>
    </TR>
    <TR>
        <TD bgcolor="#EEEEEE">* Street Address:</TD>
        <TD bgcolor="#EEEEEE"><INPUT TYPE="text" NAME="StreetAddress" onFocus="promptEntry(sUSAddress)" onChange="checkString(this,sUSAddress)"></TD>
    </TR>
    <TR>
    
        <TD bgcolor="#EEEEEE">* City:</TD>
        <TD bgcolor="#EEEEEE"><INPUT TYPE="text" NAME="City" onFocus="promptEntry(sCity)" onChange="checkString(this,sCity)"></TD>
    </TR>
    <TR>
        <TD bgcolor="#EEEEEE">* State:</TD>
        <TD bgcolor="#EEEEEE"><INPUT TYPE="text" NAME="State" SIZE=2 onFocus="promptEntry(pStateCode)" onChange="checkStateCode(this)"></TD>
    </TR>
    <TR>
        <TD bgcolor="#EEEEEE">* ZIP Code:</TD>
        <TD bgcolor="#EEEEEE"><INPUT TYPE="text" NAME="ZIP" SIZE=10 onFocus="promptEntry(pZIPCode)" onChange="checkZIPCode(this)"></TD>
    </TR>
    <TR>
        <TD bgcolor="#EEEEEE">* Phone:</TD>
        <TD bgcolor="#EEEEEE"><INPUT TYPE="text" NAME="Phone" SIZE=14 onFocus="promptEntry(pUSPhone)" onChange="checkUSPhone(this)"></TD>
    </TR>
    <TR>
        <TD bgcolor="#EEEEEE">* Email:</TD>
        <TD bgcolor="#EEEEEE"><INPUT TYPE="text" NAME="Email" onFocus="promptEntry(pEmail)" onChange="checkEmail(this, true)"></TD>
    
    </TR>
    <TR>
        <TD bgcolor="#EEEEEE">* Credit Card Type:<BR>
    
            <INPUT TYPE="radio" NAME="CreditCardType" VALUE="VISA" CHECKED>Visa<BR>
            <INPUT TYPE="radio" NAME="CreditCardType" VALUE="MASTERCARD">MasterCard<BR>
            <INPUT TYPE="radio" NAME="CreditCardType" VALUE="AMERICANEXPRESS">American Express<BR>
            <INPUT TYPE="radio" NAME="CreditCardType" VALUE="DINERSCLUB">Diner's Club<BR>
            <INPUT TYPE="radio" NAME="CreditCardType" VALUE="DISCOVER">Discover<BR>
        </TD>
        <TD bgcolor="#EEEEEE">* Credit Card Number:<BR>
            <INPUT TYPE="text" NAME="CreditCardNumber" SIZE=30 onFocus="promptEntry(pCreditCard)" onChange='checkCreditCard (this.form.elements["CreditCardType"], this)'><BR>
            * Expiration Date:<BR>
            * YYYY: <INPUT TYPE="text" NAME="ExpirationYear" SIZE=4 onFocus="promptEntry(pYear)" onChange='if (isYear(this.value) && isMonth(this.form.elements["ExpirationMonth"].value) && isDay(this.form.elements["ExpirationDay"].value)) checkDate(this, this.form.elements["ExpirationMonth"], this.form.elements["ExpirationDay"], sExpirationDate, true); else checkYear(this)'>
            * MM: <INPUT TYPE="text" NAME="ExpirationMonth" SIZE=2 onFocus="promptEntry(pMonth)" onChange='if (isYear(this.form.elements["ExpirationYear"].value) && isMonth(this.value) && isDay(this.form.elements["ExpirationDay"].value)) checkDate(this.form.elements["ExpirationYear"], this, this.form.elements["ExpirationDay"], sExpirationDate, true); else checkMonth(this)'>
            DD: <INPUT TYPE="text" NAME="ExpirationDay" SIZE=2 onFocus="promptEntry(pDay)"       onChange='if (isYear(this.form.elements["ExpirationYear"].value) && isMonth(this.form.elements["ExpirationMonth"].value) && isDay(this.value)) checkDate(this.form.elements["ExpirationYear"], this.form.elements["ExpirationMonth"], this, sExpirationDate, true); else checkDay(this, true)'> 
        </TD>
    </TR>
    <TR>
        <TD bgcolor="#EEEEEE"><INPUT TYPE="submit" VALUE="Submit" onClick="if (validateUSPersonalInfo(this.form)) displayUSPersonalInfo(this.form);"></TD>
        <TD bgcolor="#EEEEEE"><INPUT TYPE="reset" VALUE="Reset">
        </TD>
    </TD>
    </TABLE>
    </FORM>
    </BODY>
    </HTML>

  2. #2
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
    <INPUT TYPE="submit" VALUE="Submit" onClick="return validateUSPersonalInfo(this.form);">
    That should submit the form if it validates... If not, it just won't work.

  3. #3
    SitePoint Enthusiast pjdowson's Avatar
    Join Date
    May 2004
    Location
    Clinton, IA
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, that worked great!

    Phil

    Quote Originally Posted by Young Twig
    HTML Code:
    <INPUT TYPE="submit" VALUE="Submit" onClick="return validateUSPersonalInfo(this.form);">
    That should submit the form if it validates... If not, it just won't work.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •