• Resolved cmoseley

    (@cmoseley)


    Okay, so my problem is this. I’m using a javascript code to hide information in my posts and when a user clicks on a button, that information displays. But when I run the page, I get an error, “switchcontent” is not defined. It should be getting its definiation from a tag that has an id of “meta<?php the_ID(); ?>-title” which will allow the javascript to associate that button with the div that has the id “meta<?php the_ID(); ?>”.

    So my guess is that the “timing” is off. If my rudimentary understanding of WordPress is correct, after a call to index.php, the php goes and “builds” wordpress, which then goes and runs the template file. The template file first executes all the normal code in it (and thus the javascript runs), then it executes all wordpress specific PHP tags (which would by why the javascript fails, since the its relying on the wordpress specific tags to generate needed information).

    My theory is further reinforced by the fact that if I copy my code that failed from wordpress, and paste it into a static html file, the page works flawless as intended.

    So is there any way I can get the javascript to run after the template file populates all its information from wordpress specific php tags?

    I tried enclosing the javascript into WP conditional tags that would echo the code, but that didnt work either.

    For referance, the JS code i’m trying to implement is this one:
    http://www.dynamicdrive.com/dynamicindex17/switchcontent.htm

    Thanks in advanced for any help!

  • The topic ‘WP PHP Javascript Timing Help Needed!’ is closed to new replies.