Javascript by it's nature treats everything as a string, certainly all HTML controls that suport a value it will always be a string. Well more accurately everything is an object, and whenever you read that object in your code it tends to be implicitly converted or cast as a string. You have to explicitly cast your varables to a number when you require that behaviour, using the Number(string value) function e.g.
var myNumber;
myNumber = Number(document.getElementById("myTextBox").value);
if(myNumber == NaN)
alert("You must enter a number");
you can also consider parseFloat() and parseInt()
http://www.javascripter.net/faq/convert2.htm
Another usefull link:
http://www.w3schools.com/jsref/jsref_Number.asp Last edited by hollystyles; Sep 4th, 2006 at 5:50 am. Reason: Extra material
Reputation Points: 262
Solved Threads: 68
Veteran Poster
Offline 1,181 posts
since Feb 2005