This is because all events associated with the handler above are triggered by user action, not code. you can use .trigger()either .change()here to trigger the event:
$('#firstId').val(Math.floor(Math.random()*2147483647 )+1).change();
or
$('#firstId').val(Math.floor(Math.random()*2147483647 )+1).trigger('change');
source
share