Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 09-18-2008, 06:55 AM Calling JS from PHP
Extreme Talker

Posts: 196
Trades: 0
how do i get JS call to work from within a PHP page. Here is my stripped code. please note the multiple file names.

file1.php - calls JS function in file2.js (working fine).
file2.js - makes http_request to file3.php to do some stuff. (working fine)
file3.php - check some stuff in the db (working), then makes the following JS call to a <span> in file1.php (not working)
Code:
echo" <script language=Javascript><!--";
echo" document.getElementById('email_hint').style.visibility = 'visible';";
echo" //--></script>";
file1.php <span> tag
HTML Code:
<span id="email_hint" style="visibility:hidden;">Email all ready assigned to a member.</span>
My questions is why does the <span> never hear/process the getElementById call? Could it be that the call to the *document.* only refers to elements in file3.php? What say you?

FYI, file3.php is all php, it has no HTML.
empiresolutions is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-18-2008, 09:19 AM Re: Calling JS from PHP
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
This doesn't have anything to do with PHP. All of the PHP is done processing and has outputted 100%, before your browser even begins to look at the client-side code. The more likely answer is that the <span id="email_hint"... has not finished loading it at the time you are trying to access it via getElementById. document.getElementById statements can only have access to DOM elements after all of the HTML has loaded, which means they must either be inside of an "onload" event, or else at the bottom of the page.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 09-24-2008, 09:35 AM Re: Calling JS from PHP
Extreme Talker

Posts: 196
Trades: 0
SOLUTION - Thanks to *Stryker250* and all other who helped me get on the right track.

(FYI.. trim() function is part of this lib - PHP to Javascript Project, http://kevin.vanzonneveld.net/techbl...pjs_licensing/)

file2.js - Listened for the XHR "responseText" value sent back from the requested page. Depending on the reply, I did something.
Code:
        if (trim(http_request.responseText)=='email'){
            document.getElementById('email_hint').style.visibility = 'visible';
        }else if(trim(http_request.responseText)=='email_new'){
            document.getElementById('email_hint').style.visibility = 'hidden';
        }
file3.php - Depending on what was PHP'd from data send by file2.js, I echo'd either "email" or "email_new". (As is in my script, nothing else can be echo'd on the page.)

Last edited by empiresolutions; 09-24-2008 at 09:36 AM..
empiresolutions is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Calling JS from PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16830 seconds with 12 queries