In the following jquery, it works when I finish typing a value (keyup) in a textbox:-
<script type="text/javascript">
$(function(){
var minTenderNum;
$("#tenmoney").keyup(function(){
var minTenderMoney = $(this).val();
if(minTenderMoney <=1000)
minTenderNum = 3;
else if(minTenderMoney > 1000)
minTenderNum = 5;
$('#sunum').children().remove().end();
maxTenderNum = minTenderNum + 4;
for(var i=minTenderNum;i <=maxTenderNum;i++)
$('#sunum').append(new Option(i, i, true, true));
$("#uniform-sunum>span").html('');
});
});
</script>
<select id="sunum" name="sunum">
</select>
sometimes, a value already exists when the page is onload, but I have to modify the value and “key up” so that the function starts again.
If I wish to include an event for on load, how shall I modify the function? Thanks!
one of the ways to do this is On document ready You can fire a keyup event like this
add this line inside document ready callback
or even beter just call $.keyup() without any argument which will trigger keyup event on that element like this