473,326 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Calling JS from PHP

162 100+
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)
Expand|Select|Wrap|Line Numbers
  1. echo" <script language=Javascript><!--";
  2. echo" document.getElementById('email_hint').style.visibility = 'visible';";
  3. echo" //--></script>";
  4.  
file1.php <span> tag
[HTML]<span id="email_hint" style="visibility:hidden;">Email all ready assigned to a member.</span>[/HTML]

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.
Sep 18 '08 #1
3 1280
acoder
16,027 Expert Mod 8TB
PHP can't run JavaScript. You will need to either eval this JavaScript from the response or put the code in file1.js instead.
Sep 18 '08 #2
empiresolutions
162 100+
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.
Expand|Select|Wrap|Line Numbers
  1.         if (trim(http_request.responseText)=='email'){
  2.             document.getElementById('email_hint').style.visibility = 'visible';
  3.         }else if(trim(http_request.responseText)=='email_new'){
  4.             document.getElementById('email_hint').style.visibility = 'hidden';
  5.         }
  6.  
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.)
Sep 24 '08 #3
acoder
16,027 Expert Mod 8TB
That seems like a nice simple solution for your requirements. Glad you got it working and thanks for posting :)
Sep 24 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Asapi | last post by:
1. Are linkage convention and calling convention referring to the same thing? 2. Does calling convention differ between languages C and C++? 3. How does calling convention differ between...
8
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int...
7
by: Klaus Friese | last post by:
Hi, i'm currently working on a plugin for Adobe InDesign and i have some problems with that. I'm not really a c++ guru, maybe somebody here has an idea how to solve this. The plugin is...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
3
by: Mike | last post by:
Timeout Calling Web Service I am calling a .NET 1.1 web service from an aspx page. The web service can take several minutes to complete its tasks before returning a message to the aspx page. ...
2
by: Geler | last post by:
A theoretical question: Sorry if its a beginner question. Here is a quote from the MSDN explaning the C/C++ calling convention.. It demonstrates that the calling function is responsible to clean...
47
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
10
by: sulekhasweety | last post by:
Hi, the following is the definition for calling convention ,which I have seen in a text book, can anyone give a more detailed explanation in terms of ANSI - C "the requirements that a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.