Results 1 to 3 of 3

Thread: Else if else messing up

  1. #1
    Join Date
    Feb 2005
    North Carolina

    Else if else messing up

    Could someone please help me figure out why when I hit submit on this script I'm working on, it only gives me the first alert message and then goes ahead and submits the page. It seems to be ignoring the else if... and I've used the same exact format and got it to work before.

    <script language="javascript">
    function validEntries() {
    //validate form
    var txtWOID = frmOrder.txtWOID.value;
    var txtVIN = parseFloat(frmOrder.txtVIN.value);
    var txtWODate = new Date(frmOrder.txtWODate.value);
    var selectValue = frmOrder.firstService.selectedIndex;
    if (txtWOID == "") {
    alert("Please enter a work order ID number");
    return false;
    } else if (txtVIN == "") {
    alert("Please enter a VIN number");
    return false;
    } else if (txtWODate == "NaN") {
    alert("Please enter a date in the format MM/DD/YYYY");
    return false;
    } else {
    alert(txtWOID.value + "\n" + txtVIN.value + "\n" + txtWODate.value);
    return true;

    <input type=submit value="Submit" onclick="validEntries()">

    I can't figure out why it won't work and it has in the past. Thanks in advance.

  2. #2
    Instead of using the onClick event in your submit button remove that and add the onSubmit event in your form tag.

    <form ..... onSubmit="return validEntries()">

    The "return" in the onSubmit event will receive the "false" from your script and cause the form to not be submitted.

  3. #3
    Join Date
    Feb 2005
    North Carolina
    Thanks but I already tried that. I'm using Visual Studio.NET to code it and it automatically gives me an message that says "could not find any attribute onsubmit of element 'input'"

    I tried it again and it just ignores the function altogether and just submits the page.

    WAIT..... I changed it back to onclick and added the return and it worked. Thank you so much..... I would have never figured that out. I'm new at this. Thanks again.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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