Tuesday, 15 July 2014

jquery - How do I limit a text input form to a certain range of values with JavaScript? -



jquery - How do I limit a text input form to a certain range of values with JavaScript? -

so trying create input field can not go below value.

my input field normal:

<input id="something">

my javascript is:

(function () { int statesmin = 50000; int statesmax = 500000; var val = $('#something').val(); var int = parseint(((val * 100)/100), 10); //this alter text integer if(val < statesmin) { homecoming false; } if(val > statesmax) { homecoming false; } homecoming true; })();

i using jquery validation plugin if helps. want if input 40,000; want no won't work. i've heard of "listening blur event" don't know means. there anyway help me on this. how have input check see if text inputted validates function created.

here working fiddle

use blur triggers when input box loses focus

$('#something').on('blur',function(){ var statesmin = 50000; var statesmax = 500000; var val = $('#something').val(); if(val < statesmin) { alert("wont work"); homecoming false; } if(val > statesmax) { alert("wont work"); homecoming false; } homecoming true; });

javascript jquery forms validation

No comments:

Post a Comment