Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Include Statement in a JavaScript

Status
Not open for further replies.

JMaximus

Programmer
Oct 23, 2004
9
US
Is it possible?

I have a column on the left of my screen listing the company name and type of company. I would like the viewer to be able to choose to view the companies alphabetically by NAME or by TYPE.

Here is how the list appears by NAME:

Here is the page I'm trying to develop:

The script I've written looks like:

Code:
<script type="text/javascript">

function do_click( name )
{
<?php
include ('memberlistname.php');
?>);
}
function do_click( type )
{
<?php
include ('memberlisttype.php');
?>
}
</script>

....

<input type="button" value="Name" onclick="do_click( name )"/>
<input type="button" value="Type" onclick="do_click( type )"/>

I can't seem to get it work... any suggestions?
 
php is a server side langauge, you could invoke a script from javascript but not as you have shown
 
i'm a newb at programming... got a cheesy book in front of me. How do I invoke a script? Or is there a way to not to use Javascipt and only PHP to do what I'm trying?
 
A script is invoked when you point your web browser at it. The web server runs the script and pipes the output of the script to the browser.

The thing to remember is that once the HTML is piped though the network connection to the browser, the connection between the browser and the server is terminated and the PHP script stops running. All the browser then has is the HTML that was output by the script.

Anything interesting that then happens on the client side, in the browser, must be performed by client-side scripting. If that HTML output from the PHP script includes JavaScript or VBscript code, the browser can be made to run it.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
am I better off finding a solution to this in JScript as opposed to PHP to display my menu?
 
I can't advice you. Only you know that it is you want to do and how you want it done. A hierarchical menu display could be programmed in either PHP or JavaScript, depending on your needs.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
dang... that answer leaves me stumped still.

I can't quite figure out how to do it.

Does PHP have the ability to do the "onclick"-type functions that would direct it to perform one of two Include functions?
 
You can answer that question yourself.

Is your mouse connected to the server or the client?

If it's connected the the server, it may be possible to write PHP custom functions which could capture mouse actions, but PHP doesn't have them built in. If your mouse, however, is connected to your client machine, there is no way for PHP to capture mouse events as PHP will be running on the server.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
that makes sense.

Gosh I'm a rookie.

Basically, if something is clicked, there isn't a PHP function to recognize it. Which is why I originally had a Javascipt with a PHP function inside it. But I couldn't get the PHP script to work up in the script in the header.

I'll take a look at some hierarchical menu display scripts...
 
It's not just that there is no PHP function to recognize a mouse click. PHP doesn't run run on the client and so couldn't detect the click, even if there were such builtin functionality.

Don't confuse PHP with something like Mi[&cent;]ro$oft's VBscript, which has interpreters that can run on both the server and the client. PHP is solely a server-side programming language.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I've been thinking this'll be a Javascript.

I know the script for menu tabs but I already have them running once on the page and am unable to make them work in two different spots on the page.

I'll have to find another solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top