Skip to content Skip to sidebar Skip to footer

I Want To Show Error Message Beside My Textbox Rather Than Alert In Onkeyup Event

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

Solution 1:

Create a span beside input then change your code as

$(function() {
  $("#id_part_pay").next('span').hide(); //Hide Initially
  $("#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 and Show
      return;
    }
    
    
    if (input < 20 || input > 100) {
      span.text("Value should be between 20 - 100").show();//Set Text and Show
      return;
    }
    
    span.text('').hide();//Clear Text and 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>

Post a Comment for "I Want To Show Error Message Beside My Textbox Rather Than Alert In Onkeyup Event"