NetTalk Central

Author Topic: Javascript OnLoad and OnUnload on Forms - Google geocoding  (Read 4309 times)

Rob Mikkelsen

  • Full Member
  • ***
  • Posts: 107
    • Yahoo Instant Messenger - flashpott
    • View Profile
    • Email
Javascript OnLoad and OnUnload on Forms - Google geocoding
« on: February 28, 2010, 10:01:38 AM »
NTWS 4

I am implementing Google geocoding and maps on my app.  In all the examples I have seen, a couple objects need to be initialized on a page load, and cleaned up when the page unloads.  I cannot find the <body onload=" embed on the form, and only the onload but not onunload on a page.

Where do I access the javascript to init and kill these objects?  Do I need to check to see if it is initialized and do so if necessary whenever an onchange() event is triggered?

Thanks!

Rob

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Javascript OnLoad and OnUnload on Forms - Google geocoding
« Reply #1 on: February 28, 2010, 10:04:47 PM »
Hi Rob,

Without trying the specific JavaScript you're asking about....
In general you don't need specific embed points, because it's all just done as <script> code on the page.
So you can embed whatever script you want / need, at more or less any place on the form.

cheers
Bruce

Rob Mikkelsen

  • Full Member
  • ***
  • Posts: 107
    • Yahoo Instant Messenger - flashpott
    • View Profile
    • Email
Re: Javascript OnLoad and OnUnload on Forms - Google geocoding
« Reply #2 on: March 01, 2010, 07:29:27 PM »
Bruce,

At the risk of divulging my ignorance regarding Javascript, my understanding is that all Javascript required an event to trigger the functions.  In many cases, this is done via the <body onload="..."> command.  Is it possible to trigger Javascript code just by placing the code inline without tying it to an event?  All the references I have read tie it to an event.

Right now, I initialize the map object when the first field is selected which works but looks, to use the technical term, ugly.

On another note - is there a good Javascript editor available?  Right now, the only feedback that I get when I hose up my Javascript is that everything stops working.  Therefore, coding Javascript becomes a game of millimeters...  Change a line, recompile, make sure it doesn't break - change another line, etc...

Cheers!

Rob

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Javascript OnLoad and OnUnload on Forms - Google geocoding
« Reply #3 on: March 02, 2010, 11:09:58 PM »
Hi Rob,

You can put JavaScript just inline in the html, without it being tied to any event.
The "onload" technique makes it easier to add javascript to a page, without actually putting any javascript on the page, but it's not a requirement.

"unload" is obviously more of a requirement though since that presumably happens well after the page has been loaded.

so in your html, if you have code like this;
<script>
whatever();
</script>
then the whatever function is run.

You'll see that in a generated browse, for example, there's something like this;
<script type="text/javascript" defer="defer">var BrowseUserRights=new browseTable('BrowseUserRights','BrowseSystemFilter_frm','USS:Guid',1,'browseuserrights_browsesystem',1,1,1,'BrowseSystem','UpdateUserRights','_self',1,'Are you sure you want to delete this record?','4C7tZ4DeQ8VWyHEG','','_self','UpdateUserRights');
BrowseUserRights.setGreenBar('','','','');
BrowseUserRights.greenBar();
</script>

This code initialises the browse object, and runs the greenbar function if it's appropriate.
the "defer" attribute means that it waits for the page to finish loading before the code executes.

cheers
Bruce

Rob Mikkelsen

  • Full Member
  • ***
  • Posts: 107
    • Yahoo Instant Messenger - flashpott
    • View Profile
    • Email
Re: Javascript OnLoad and OnUnload on Forms - Google geocoding
« Reply #4 on: March 05, 2010, 11:02:49 AM »
Fantastic!  Just goes to show - you can't always believe what you read in books.  This should simplify things considerably.

Rob