Alternatives to body onload not working

Discussion in 'Javascript' started by bbcrock, Jul 26, 2006.

  1. bbcrock

    bbcrock Guest

    I take my hat in hand with a question.

    I have dynamically named form elements set in divs based on a
    server-side language. I am displaying these using DHTML in a
    display:none, display:block format.

    Due to some code (and deadline) issues I do not have the total number
    of form elements set by the time the body tag is run. I wanted to have
    a script tag later on in the document which reads something like:

    <query>

    <builds div element1i1, element1i2, etc>

    <script language="javascript">
    document.getElementById(' query variable '+1).style.display = 'block';
    </script>

    </query>

    However the JavaScript code does not run. Alerts run inside the code
    consistently, but the other code does change the display to block.
    also tried running this same code as on OnFocus

    Any suggestions or links to articles that discuss this?

    thanks!

    Don
     
    bbcrock, Jul 26, 2006
    #1
    1. Advertisements

  2. bbcrock

    Randy Webb Guest

    said the following on 7/26/2006 4:31 PM:
    Why? Have the server set it.
    window.onload=someFunction;

    function someFunction(){
    document.getElementById(' query variable '+1).style.display = 'block';
    }

    Where the query variable is inserted by the server.
     
    Randy Webb, Jul 27, 2006
    #2
    1. Advertisements

  3. bbcrock

    bbcrock Guest

    Sorry, yeah, I wasn't being very clear.

    The number and name of those functions would be dynamic based on data
    from the database so I wouldn't know their names during onload. I got
    caught in a catch 22 where I couldn't preload all the functions in the
    body onload because the data would be determined later in the page.
    You know, can't move this code here, because it relies on this code
    over here and as the page loads, there's a sequential logic to it. I'm
    on round three of client modification, so my code is not as robust as
    it was when I planned it out.

    What I did that's working at the 95% level and needs to be slightly
    debugged was to go in at the onFocus and run the dynamic number of
    functions based on using the substring function and having similarly
    named divs. There's a slight bug, but since all the div names follow a
    pattern, then that seems to do the trick.

    Don
     
    bbcrock, Jul 27, 2006
    #3
  4. bbcrock

    Randy Webb Guest

    said the following on 7/26/2006 10:13 PM:
    Huh? You are telling me that your server side code generates code that
    is unknown to you until that code is loaded in a browser? I don't
    believe you. If the server generates that name, then it knows that name,
    and you can define anything you want, simply define it when you need it
    (the first time it appears in the page). Its not a catch 22.
     
    Randy Webb, Jul 27, 2006
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.