Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Apr 2005
    Location
    USA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Form Validation Error!

    I keep getting a syntax error for this. It says the error is on line 8, char 9, but I can't find anything wrong...Does anyone know how to fix it?

    function confirmSubmit() {
    if (document.forms[0].name_home.value == ""
    || document.forms[0].address_home.value == ""
    || document.forms[0].city_home.value == ""
    || document.forms[0].state_home.value == ""
    || document.forms[0].zip_home.value == "") {
    window.alert("You must enter your home information");
    return.false;
    }
    else if (document.forms[0].name_billing.value == ""
    || document.forms[0].address_home.value == ""
    || document.forms[0].city_home.value == ""
    || document.forms[0].state_home.value == ""
    || document.forms[0].zip_home.value == "") {
    window.alert("You must enter your home information");
    return.false;
    }

    else if (document.forms[0].area.value == ""
    || document.forms [0].exchange.value == ""
    || document.forms [0].phone.value == "") {
    window.alert("You must enter a phone number");
    return.false;

    }

    else if (document.forms[0].password.value == ""
    || document.forms[0].password_confirm.value == "") {
    window.alert("You must enter a password");
    return.false;
    }
    }

    function confirmReset() {
    var resetForm = confirm("Are you sure you want to reset the form?");
    if (resetForm == true)
    return true;
    return false;
    }



  • #2
    New to the CF scene
    Join Date
    Apr 2006
    Location
    Illinois
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ah fortunately this is an easy fix.

    all you have to do is arrange your if statement like this...

    Code:
    if(someElement.value == "" && someElement.value == null
    || someElement2.value == "" && someElement2.value == null)
    {
    execute this code.....
    }
    you have use use not only == "" but also == null. That should take care of your problem.

    LiveScript
    In a world of complexities... Simplicity is the key.
    www.livescript.net

  • #3
    New to the CF scene
    Join Date
    Apr 2005
    Location
    USA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    still getting the same error, line 8, char 10 now.







    function confirmSubmit() {
    if(document.forms[0].name_home.value == "" && document.forms[0].name_home.value == null
    || document.forms[0].address_home.value == "" && document.forms[0].address_home.value == null
    || document.forms[0].city_home.value == "" && document.forms[0].city_home.value == null
    || document.forms[0].state_home.value == "" && document.forms[0].state_home.value == null
    || document.forms[0].zip_home.value == "" && document.forms[0].zip_home.value == null) {
    window.alert("You must enter your home information");
    return.false;
    }

    else if(document.forms[0].name_billing.value == "" && document.forms[0].name_billing.value == null
    || document.forms[0].address_billing.value == "" && document.forms[0].address_billing.value == null
    || document.forms[0].city_billing.value == "" && document.forms[0].city_billing.value == null
    || document.forms[0].state_billing.value == "" && document.forms[0].state_billing.value == null
    || document.forms[0].zip_billing.value == "" && document.forms[0].zip_billing.value == null) {
    window.alert("You must enter your billing information");
    return.false;
    }

    else if (document.forms[0].area.value == "" && document.forms[0].zip_billing.value == null
    || document.forms [0].exchange.value == "" && document.forms[0].exchange.value == null
    || document.forms [0].phone.value == "" && document.forms[0].phone.value == null) {
    window.alert("You must enter a phone number");
    return.false;

    }

    else if (document.forms[0].password.value == "" && document.forms[0].password.value == null
    || document.forms[0].password_confirm.value == ""&& document.forms[0].password_confirm.value == null) {
    window.alert("You must enter a password");
    return.false;
    }
    }

    function confirmReset() {
    var resetForm = confirm("Are you sure you want to reset the form?");
    if (resetForm == true)
    return true;
    return false;
    }

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    You have writtem return false with a dot in the middle
    replace
    return.false
    with
    return false

    livescript, your ideea seems not a good one. Do you think a value could be an empty string AND a null the SAME time?

    It looks like the reset function is wrong. I guess the whole function has no sense. If the user presses the Reset button, that means he wants to reset the form, why asking for confirm?

    (I hate most of the stupid Windows alerts "Are u sure you want to...". Damn I am sure, Mr. Gates, do you think I am dumb? )

    Anyway, if you want that by all means:
    PHP Code:
    function confirmReset() {
    var 
    resetForm confirm("Are you sure you want to reset the form?");
    return 
    resetForm;

    Last edited by Kor; 05-09-2006 at 02:45 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New to the CF scene
    Join Date
    Apr 2005
    Location
    USA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, it works now

  • #6
    New to the CF scene
    Join Date
    Apr 2006
    Location
    Illinois
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As far as the null goes it not setting an object such as a textbox to "null" such as a sting its setting it to null as in no value. With some opensource and linux browsers such as FireFox or Konquerer. The function will not work unless you have null too. Thats why I mentioned that, since I didnt know what browser he was using. I do feel stupid however since I didnt notice the return.false instead of return false.
    In a world of complexities... Simplicity is the key.
    www.livescript.net

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by livescript
    As far as the null goes it not setting an object such as a textbox to "null" such as a sting its setting it to null as in no value. With some opensource and linux browsers such as FireFox or Konquerer. The function will not work unless you have null too. Thats why I mentioned that, since I didnt know what browser he was using. I do feel stupid however since I didnt notice the return.false instead of return false.
    Maybe. It is not the null value I was against. It was the AND operator (&&). I guess that should have been OR (||)
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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