SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
Thread: help with a function please
-
Dec 5, 2006, 17:46 #1
- Join Date
- Dec 2006
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
help with a function please
i've got a problem validating my text field. when my calculation is in the display and i click equals if the last character is not a number then it alerts the user the calculation must end with a digit but it also alerts when the calculation in the display is e.g. 9+9 which is correct yet alerts saying calculation must end in a digit and then performs the calculation after clicking ok, basically i just want it to alert when the last character is not a number.
any help greatly appreciated
here's the code i've got for it. (when calling the functions i've got onClick="validateIt();equals();"
Code:function equals() { document.calculator.display.value=eval(document.calculator.display.value); } function validateIt() { var input=document.calculator.display.value; var length=input.length-1; if(isNaN(input.charAt(length))); alert("your calculation must end in a digit") }
-
Dec 5, 2006, 18:19 #2
- Join Date
- Sep 2006
- Posts
- 731
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Bookmarks