javascript - I want to show error message beside my textbox rather than alert in onkeyup event -


i want show error message beside textbox rather alert in onkeyup event

html

<input type="textbox"    id="id_part_pay"     value="<?php echo $listing['part_pay'];?>"    name="part_pay"  /> 

javascript

$("#id_part_pay").keyup(function() {     var input = $('#id_part_pay').val();     var v =input % 10;     if (v!==0)     {       alert("enter percentage in multiple of 10");     }     if(input<20 || input>100)      {       alert("value should between 20 - 100");       return;     } });` 

create span beside input change code as

$(function() {    $("#id_part_pay").next('span').hide(); //hide    $("#id_part_pay").keyup(function() {      var input = $(this).val();            var v = input % 10;      var span = $(this).next('span'); //get next span element            if (v !== 0) {        span.text("enter percentage in multiple of 10").show(); //set text , show        return;      }                  if (input < 20 || input > 100) {        span.text("value should between 20 - 100").show();//set text , show        return;      }            span.text('').hide();//clear text , hide          });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <input type="textbox" id="id_part_pay" value="10" name="part_pay" />  <span></span>


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -