I want to show error message beside my textbox rather than 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 be between 20 - 100");
return;
}
});`
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.