window.onload multiple functions

Discussion in 'JavaScript' started by ardjuna, May 24, 2008.

  1. #1
    Need help!!!
    I have quite complicated form, which you can view on my web page:
    http://knihovna1.own.cz/form1/
    Code (markup):
    The JavaScript (form.js) is quite huge. It has around 680 rows, and about 20 functions. Nearly all the functions are for hiding/showing different elements in the form. If you choose or click some option (select-->option, checkbox, radio button), then some element shows up (fieldset, table, row or just a single cell). In the script I call window.onload function. Now I would like to divide the script into smaller pieces (let's say for each hiding/showing option just one single script file), so that I can edit it, and not be lost inside it. Please, can you help me, and tell me, what should I do for it to work properly? I'm quite new to JavaScript, so I would appreciate if you can be as concrete as possible (step-by-step guide).
    Thanks to all who will reply!!!
    Ardjuna (ardjuna@seznam.cz)
     
    ardjuna, May 24, 2008 IP
  2. vurentjie

    vurentjie Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    there are a couple of options to look at, window.onload is one, that is if you want to run some function as soon as the window has finished loading content - this is good as it ensures that what ever element you are working with has already been loaded, otherwise you can also use setTimeOut (as many times as needed , to run a function however many miliseconds after loading), there is also setInterval which allows you to run a function on a page every 5 seconds for example,

    I had a look at your page, crazy language!, basically you have a form setup that changes the content of a wrapper either with innerHTML, or display settings etc, basically all you need to do for some of the things is organize your different events and build specific functions for each, then allocate them each to a script source, then include each script source that is needed in your page,

    <script src=......etc.

    after that try to find what data needs to be sent to functions on page initial load and use setTimeOut('function()',interval_after_load set to zero);

    that is some of my advice.
     
    vurentjie, May 24, 2008 IP