SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form Validation - What am I missing?

    Hi,

    I've got a form validation function that checks to make sure a form value is 19 characters long:

    <SCRIPT LANGAUGE="JavaScript">
    function checkrequired(){
    if (document.data.card_number.value.length > 19 ||document.data.card_number.value.length < 19)
    {
    alert("Card Number Must be 19 Characters")
    return false
    }
    }
    </script>

    Call it using:
    <FORM NAME="data" METHOD=POST ACTION="myscript.asp" onSubmit="checkrequired(this)">

    The alert box pops up if anything other than 19 characters is entered, you hit OK on the alert box, but you're still taken to myscript.asp?

    What am I missing?

    Thanks

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    onSubmit="return checkrequired(this)"

    You also don't need the double-condition

    if ( document.data.card_number.value.length != 19 )
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by beetle
    onSubmit="return checkrequired(this)"

    You also don't need the double-condition

    if ( document.data.card_number.value.length != 19 )
    I was SURE I tried that...

    Apparently not.

    Thanks


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
  •