erme Posted July 16, 2013 Share Posted July 16, 2013 Hi, I have a input with a number as a value, say 1.55. I want to allow the user to be able to increase the number but not decrease it. Is this possible? Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/280207-allow-increase-of-number-but-not-decrease/ Share on other sites More sharing options...
Solution fastsol Posted July 16, 2013 Solution Share Posted July 16, 2013 This is a working example, there are a couple ways you could tweak this depending on your needs. http://jsfiddle.net/fastsol/6nXxe/1/ I wanted to do the check on keyup but then you couldn't even change the last number cause it would obviously be less than the 1.55, so went with focusout instead. Quote Link to comment https://forums.phpfreaks.com/topic/280207-allow-increase-of-number-but-not-decrease/#findComment-1440933 Share on other sites More sharing options...
.josh Posted July 16, 2013 Share Posted July 16, 2013 I assume that this input field eventually comes with some kind of submit button.. alternatively you could validate it onclick or onsubmit. However, just want to point out that seeing as how this is javascript, the user can simply disable javascript or overwrite your js function to do whatever the hell he wants.. you should be validating this server-side. Quote Link to comment https://forums.phpfreaks.com/topic/280207-allow-increase-of-number-but-not-decrease/#findComment-1440976 Share on other sites More sharing options...
erme Posted July 17, 2013 Author Share Posted July 17, 2013 (edited) This is a working example, there are a couple ways you could tweak this depending on your needs. http://jsfiddle.net/fastsol/6nXxe/1/ I wanted to do the check on keyup but then you couldn't even change the last number cause it would obviously be less than the 1.55, so went with focusout instead. Perfect, however is there an obvious reason why it wouldn't work in IE? Actually it does. I'm just being stupid! Edited July 17, 2013 by erme Quote Link to comment https://forums.phpfreaks.com/topic/280207-allow-increase-of-number-but-not-decrease/#findComment-1441022 Share on other sites More sharing options...
Irate Posted July 17, 2013 Share Posted July 17, 2013 For this feature you can use closures to capture the state of the variable, but as .josh said, please, validate it server-side. Quote Link to comment https://forums.phpfreaks.com/topic/280207-allow-increase-of-number-but-not-decrease/#findComment-1441046 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.