javascript - Jquery on page load not working -
i doing request in php value, taking value , inputting textfield's value, have text-fields value call json request.
it works on input , change, on page load. here code below:
$(document).ready(function() { var runningrequest = false; var request; $('input#asd3').on('load', function(e) { var $q = $(this); if(runningrequest){ request.abort(); } runningrequest=true; var mystring = self.location.href; var mysplitresult = mystring.split("?"); request = $.getjson('search',{q:$q.val()},function(data){ showresults(data,$q.val()); showresults2(data,$q.val()); runningrequest=false; }); }); }); the html
<input type="text" id="asd3" name="asd3" value="<?php echo $name ?>" class="form-control" autocomplete="off" placeholder="search name..." class="input-block-level" placeholder="search..." style="width:100%; display:none;" />
https://developer.mozilla.org/en-us/docs/web/events/load
the load event related elements pertain external resources. window document, images, iframes, etc. input element not rely on , not have load event.
if want logic happen on 'page' load should bind window or document. try changing...
$('input#asd3').on('load', ... to
$(document).on('load', ...
Comments
Post a Comment