0

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>
4
  • 4
    What's wrong with putting it inside that last code block? Commented Feb 25, 2013 at 1:23
  • What is the variables() plugin that you're using? Commented Feb 25, 2013 at 1:29
  • What do you want to trigger exactly? Commented Feb 25, 2013 at 1:30
  • You second code block (with the <script> tag) should fire when the document is done loading due to you having $(function() {...}), as per jQuery's .ready() docs (api.jquery.com/ready). Assuming $ is jQuery at least... Commented Feb 25, 2013 at 1:32

1 Answer 1

2

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() {...}).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.