bind199 Posted March 26, 2008 Share Posted March 26, 2008 lo i need a quick data validation for a text box so taht it checks to see if number entered in a box is a number after all and is a whole number(integer) the name of the text box is amount Thanks for help Link to comment https://forums.phpfreaks.com/topic/97910-quick-function-question/ Share on other sites More sharing options...
Psycho Posted March 27, 2008 Share Posted March 27, 2008 function isInt (value) { return (!isNaN(value) && (value==Math.round(value)); } Link to comment https://forums.phpfreaks.com/topic/97910-quick-function-question/#findComment-501861 Share on other sites More sharing options...
bind199 Posted March 28, 2008 Author Share Posted March 28, 2008 ok this is an addendum to the first post, i want to validate the text box which takes the value and has to be between 1 and 100 would it be a if statement like if (amt > 100 ll amt <1) alert "incorrect format"? the text box is called "amt" Link to comment https://forums.phpfreaks.com/topic/97910-quick-function-question/#findComment-502695 Share on other sites More sharing options...
Psycho Posted March 28, 2008 Share Posted March 28, 2008 function validateAmount (value) { if (isNaN(value) || value!=Math.round(value)) { alert('The value must be an integer.'); return false; } else if (value<1 || value >100) { alert('The value must be between 1 and 100.'); return false; return true; } Link to comment https://forums.phpfreaks.com/topic/97910-quick-function-question/#findComment-502820 Share on other sites More sharing options...
bind199 Posted March 30, 2008 Author Share Posted March 30, 2008 thanks for all ur help. One last thing i promise. I am still alittle confused on what to put in the "value" space. For example the Text box named IRate would i put function validateAmount (IRate.value) ? or something similar. thanks for all the help. Regards Link to comment https://forums.phpfreaks.com/topic/97910-quick-function-question/#findComment-505129 Share on other sites More sharing options...
Psycho Posted March 31, 2008 Share Posted March 31, 2008 No, you would call tyhe function like this: validateAmount (IRate.value) Assuming "IRate" is an object reference for the field. You would need to create a trigger such as onblur, onchange, onsubmit, etc. And also have proper alerts or functions to handle if the response is negative. You didn't post any code so I can't offer any suggestions on how to best implement this - I jsut created a function that will return true/false based upon the parameters you asked. Link to comment https://forums.phpfreaks.com/topic/97910-quick-function-question/#findComment-505343 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.