javascript - Allow only number in text box based on consecutive id -


here fiddle allow numbers.

i want in based on id.

so created fiddle

$(document).ready(function () {   //called when key pressed in textbox   $("#quantity").keypress(function (e) {      //if letter not digit display error , don't type      if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {         //display error message         $("#errmsg").html("digits only").show().fadeout("slow");                return false;     }    }); }); 

how can series of id quantity1,quantity2, this..

update :

i can't use class name.. how can id

all you've match id's simple. see fiddle.

here's part code -

$(document).ready(function () {   //called when key pressed in textbox     $("[id^=quantity]").keypress(function (e) {      //if letter not digit display error , don't type      if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {         //display error message         $("#errmsg").html("digits only").show().fadeout("slow");                return false;     }    }); }); 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -