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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2004
    Location
    about:blank;
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JS Form Validation & Numbers

    I'm using an old javascript form valadation script, to let users input a number. This number pertains to an online rpg game, that has treasure trail clues. Some are Choords, used with a sexant to find.

    Anyway, the problem happens with choords begining with "0". I have a total of 26 actual options. The first 4 options that begin with zero work fine. However, any choord string beging with zero after the first 4, do not. (Any of them, the script just moves down to the final alert.) Numbers that begin with anything from 1-9, works fine.

    Here's an example of my script;

    function valid(form) {
    var field = form.choord;
    var choord = field.value;
    if (!choord) {
    alert("You must indicate a choord.");
    return false;
    } else if (choord == 01260801) {
    alert("");
    return true;
    } else if (choord == 02482230) {
    alert("");
    return false;
    } else if (choord == 21241754) {
    alert("");
    return true;
    } else {
    alert("Sorry, I could not find that location.");
    field.focus();
    field.select();
    return false;
    }
    }

    Why would this be happening? Could anyone point me in the right direction here? Also, here is a version of the full script.

    http://liquidclock.net/load.lcf?id=treasuretrails

    Any help, would be a blessing. Thanks for any input guys!
    Last edited by Midd_Knight; 09-21-2004 at 11:16 PM.

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    It may be losing the first zero, because you have them specified as a number, you could try specifying them as strings by enclosing them in quotations. This is just a guess, but worth a shot.

    ie.

    Code:
    else if (choord == "01260801") { 
    alert("");

    basscyst
    Helping to build a bigger box. - Adam Matthews

  • #3
    New to the CF scene
    Join Date
    Sep 2004
    Location
    about:blank;
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No idea why I didn't think of this. That works, thanks a lot Basscyst!

  • #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 could try specifying them as strings
    I should say even that you must specify them as strings because, remember next time, the input values are always strings, not numbers!
    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
    •