Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    A text Game... Javascript Submit...

    I've been working on a new javascript game for a while now. At the end of the game I've been trying to get my javascript to submit information to a php script, which, in turn, writes that highscores data to a file. I need the script to be executed once the last image on the final page loads. SO... I was wondering two things.

    1) How do I get a javascript to autosubmit two simple variables to a php script.
    2) How do I place that javascript in my image tag?

    <img src=congratulations.jpg onload='javascript: var1=time; var2=name;

    I'm totally lost after this...

    Any help?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    First of all, the data to be submitted must be within a form.

    <FORM name ="MyForm" action = ...............>

    The submission of the form can only be triggered by an event handler such as onBlur, onClick, onmouseOver and so on. Also onLoad - the load event does not occur until all the elements on the HTLM web page have been loaded so the onLoad event handler will only run after all elements are present on a page.

    But you cannot attach the onLoad event handler to an image in the way you are trying to do.

    Also remember that a further (second) onLoad event handler assigned in the <BODY> tag will overwrite one in a script. In other words, you can only have one onLoad event handler.

    Hope this helps.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •