SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: What's wrong?

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2002
    Location
    Florida
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What's wrong?

    I tried using the following script to make sure all required fields are filled out on a sign-up form. But it is not working. Any clue why not?


    <script language="javascript">
    function validateForm(){
    var msg = "";

    if(document.frmMain.fname.value.length == 0)
    msg += "The first name is blank.\n";

    if(document.frmMain.lname.value.length == 0)
    msg += "The last name is blank.\n";

    if(isNaN(Date.parse(document.frmMain.DOB.value)))
    msg += "The date of birth is not a valid date.\n";

    if(document.frmMain.email.value.length == 0)
    msg += "The email is blank.\n";

    if(document.frmMain.street1.value.length == 0)
    msg += "The street address is blank.\n";

    if((document.frmMain.us_city.value.length > 0) || (document.frmMain.us_zip.value.length > 0)){

    if (document.frmMain.us_city.value.length == 0)
    msg += "The US city is blank.\n";

    if (document.frmMain.us_zip.value.length == 0)
    msg += "The US Zip code is blank.\n";
    }

    if((document.frmMain.intl_city.value.length > 0) || (document.frmMain.intl_postal_code.value.length > 0)){

    if (document.frmMain.intl_city.value.length == 0)
    msg += "The international city is blank.\n";

    if (document.frmMain.intl_postal_code.value.length == 0)
    msg += "The international postal code code is blank.\n";
    }
    if((document.frmMain.us_city.value.length == 0) && (document.frmMain.intl_city.value.length == 0))
    msg += "The city is blank.\n";

    if(msg.length > 0){
    alert("The following errors occurred with your input:\n\n" + msg);
    return false;
    }else{
    return true;
    }

    }
    </script>

  2. #2
    SitePoint Enthusiast rash's Avatar
    Join Date
    Dec 2004
    Location
    Earth
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a none JavaScript thread. Pls move your question to the JS-section.
    RASH.

  3. #3
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    NY, USA
    Posts
    712
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tonybear
    I tried using the following script to make sure all required fields are filled out on a sign-up form. But it is not working. Any clue why not?
    Are you getting any errors? if so what are they.


    also do you have this in the <form> tag:

    Code:
    onsubmit="return validateForm();"


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
  •