Monday 15 February 2010

javascript - jQuery realtime validation not working -



javascript - jQuery realtime validation not working -

i trying validate fields in webpage s input can take number. not working. html:

<div class="form-group has-feedback"> <label class="control-label" for="mcc">gsm.identity.mcc</label> <br/> <input type="text" class="form-control" name="mcc" id="mcc" value="${mcc}"> <span class="glyphicon form-control-feedback"></span> </div>

and script:

<script type="text/javascript"> $(document).ready(function(){ $("#mcc").on('keypress',function(){ if(!$.isnumeric(this.val())){ $(this).parent("div").removeclass("has-feedback").addclass("has-error"); } else{ $(this).parent("div").removeclass("has-feedback").addclass("has-success"); } }); }); </script>

i have tried altering , changing in someways, gives no result whatsoever. note: using bootstrap css , styles, "hass-error" class marks input red

change this:

if(!$.isnumeric(this.val())){

to this:

if(!$.isnumeric(this.value)){

or more jquery way:

if(!$.isnumeric($(this).val())){

and in else part, may in case need remove has-error class too:

else{ $(this).parent("div") .removeclass("has-feedback has-error") .addclass("has-success"); }

javascript jquery html css validation

No comments:

Post a Comment