I have drop down list and onchange event I have an ajax call
$('#id').change(function() {
// ajax call
});
But I want ajax call to be called :
- onchange
- onload
I have logic somewhat like this:
<script>
$function({
myfunction();
$('#id').change(function() {
myfunction();
});
});
function myfunction(){
// ajax call
}
</script>
But is there any efficient way of doing this, any jquery event that call handle both performing OR functionality like this:
if (onchange || onload)
// ajax call
I apologize for title.
Since you want the event bound on two separate objects, not just two separate events, there isn’t really a better way to do it than what you’ve written. If you wanted to bind two events to the same element, you could do the following:
Unfortunately,
<select>s won’t fire load events when the page loads, so you’re stuck.