Reputation: 95
What instruction should I use so this function is executed once the page loads instead of on click? I tried:
window.onload=function () {
("#geocomplete").trigger("geocode");
but the code above didn't work.
<script>
$(function () {
$("#variables").variables({
map: ".map_canvas",
details: "form",
types: ["calculations", "grades"]
});
$("#submit_button").click(function () {
$("#variables").trigger("calculations");
});
});
</script>
Upvotes: 0
Views: 418
Reputation: 12419
window.onload
happens before jQuery's event $(document).ready()
(which as you're probably aware, you've set up using the shorthand version, $(function() {...})
).
So you're trying to trigger an event that hasn't been set up yet.
As @David pointed out, you could just put the trigger code at the end of your existing code inside $(function() {...})
.
Upvotes: 2