Jump to content

Calling JS from PHP


cesarcesar

Recommended Posts

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)

echo" <script language=Javascript><!--";
echo" document.getElementById('email_hint').style.visibility = 'visible';";
echo" //--></script>";

 

file1.php <span> tag

<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.

Link to comment
Share on other sites

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/techblog/article/phpjs_licensing/)

 

file2.js - Listened for the XHR "responseText" value sent back from the requested page. Depending on the reply, I did something.

        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.)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.