View Full Version : JS Form Validation & Numbers

09-21-2004, 11:14 PM
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) {
return true;
} else if (choord == 02482230) {
return false;
} else if (choord == 21241754) {
return true;
} else {
alert("Sorry, I could not find that location.");
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.


Any help, would be a blessing. Thanks for any input guys!

09-21-2004, 11:20 PM
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.


else if (choord == "01260801") {


09-21-2004, 11:40 PM
No idea why I didn't think of this. That works, thanks a lot Basscyst!

09-22-2004, 10:19 AM
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!