homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

write 'back' a variable needed earlier in a page?
printing a variable created in an included page

 12:16 pm on Nov 18, 2013 (gmt 0)

This is perhaps a (very) silly question.

I have a php page with javascript, and further down the page I 'include' another php script that generates a series of boxes. I need to pass the id's of those boxes into the javascript that will execute on page load.

The thing is, if I 'echo' the variable required ~before~ the 'included' php script, I get an 'undefined var' error. I could write the javascript after the php 'include', but the javascript must stay in the head because it executes on load.

What obvious thing am I overlooking? This is driving me crazy.




 3:21 pm on Nov 19, 2013 (gmt 0)

This is very much a JavaScript question, not a PHP question.

two ideas for you.
1) trigger the javascript on a "domready" event, or on page load.
2) put the script at the end of the page.

in jQuery, it's like this:

// the page is loaded, so you can use a selector
// to find the ids on the page

because it executes on load.

I there's a misunderstanding there. If the page is loaded, the elements with their IDs will exist. Also, you don't have to have things in the <head> in order for them to execute on load.


 6:29 am on Dec 2, 2013 (gmt 0)

Sorry in the lateness of my reply, and thanks for your answer.

Yes, that was about it, I was overthinking the question. In fact, I don't quite remember now ~what~ I was trying to do ; P

Right, I wanted to pass the (dynamically-generated) id's of boxes to the 'execution' script - javascript was indeed the answer. Thanks again ; )

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved