Re: javascript and php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Perry, Matthew (Fire Marshal's Office) wrote:
Hello all,

I am having difficulties working with a JavaScript menu that should load on
each page of my intranet site.
[snip]
hint - you're already on the wrong list.  Read on.

Here is a brief background of the problem:
[snip]
4) I am using a JavaScript application for my navigation menu. I
chose this because I need collapsing menus. There are lots of functions
under each category; if I were to use HTML for the menu, my users would have
to scroll way down to get to where they want to go - especially the ones
still using 800X600 monitor resolution. A php function calls the JavaScript
menu and changes what is displayed based on the session array data.


Here is the problem:

 My JavaScript menu DOES NOT always display.  It displays about 95% of the
time.  When it displays, it displays correctly (based on the session data).
When it doesn't display, I hit reload and it usually reappears.  What's
worse, it seems to happen randomly!  I could click the same link 10 times
and it will work perfectly.  The 11th time it might not show up.

Here is the small amount of information I know about the problem:

I have read through the list server achieves and think the problem may lie
with the fact that Javascript has to run at the Web Browser end and PHP has
to run at Server Side.  This probably explains how it is possible that the
two are not in sync but it does not explain WHY this happens about 5% of the
time.  It also does not explain why it happens only to the JavaScript while
always displaying the results of my php functions.
[snip]
Your problem is that your javascript menu functions don't use an onload handler. What you need to realize is that the DOM may not have finished loading all the objects in the page, even though the object may have been printed out to the browser.


so the (pseudo code) equivalent of:
---
<input type="submit" id="op" name="op" value="Operation" />
<script language="JavaScript">
operation_button = my_find_item_func('op');
</script>
---
may be holding null for 'operation_button' because op hasn't been added to the DOM yet. You have to wait until the page fully loads, then call a function to find that 'op' button.


The reason it works most of the time, is probably because it's not being triggered until you mouseover the menu. Try loading the page with your mouse nowhere near where the menus should go, and the problem may 'disappear' (note: obviously not a solution). There's no guarantee, but that's a distinct possibility.

Search for body.onload or window.onload functions.

Also, whatever dropdown code you're using - if they don't describe doing this, you probably can find better. Any sane packaged dropdown code should be explicit about requiring the user to use onload to instantiate things.

Cheers,
--
- Martin Norland, Database / Web Developer, International Outreach x3257
The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux