I expect that I really need to give more background on this question, but...
I am curious if there is a way to access the Document Object Model (DOM) in IE or Netscape via PHP native scripting in order to facilitate dynamic page generation such as is available in JavaScript or VBScript (see Example 1 below). Actually, the problem isn't just accessing the DOM from within PHP scripting, but being able to reference a PHP script from within a HTML tag as indicated in Example 2 as well.
Example 1:
/* from within a 'strict' DTD HTML/DHTML/XHTML page */
<?php
// some script here defining the function
// try setting the object color property
document.getElementByID("MyAnchorTag").style.color = "red";
// some script here closing out the function
?>
-- This should change the color of the anchor tag text to red, but instead I can't use this syntax becuase it can't recognize what document.xxx means. --
I need a way to do Event Handling inside a 'strict' DTD. Currently I have PHP pages (like index.php) which handle initial requests to the server, but I can't do DHTML like control from within PHP without mixing JavaScript or VBScript (client or server side) to handle the dynamic elements of the page [even something as simple as Anchor color links on a 'mouseover' event].
The World Wide Web Consortium (W3C @ http://www.w3c.org) discuss a great deal about the standard Document Object Model that browsers are supposed to (and in general do) support. I just can't find a way to access this DOM from within PHP scripts.
Anyone have any advice? How can this be accomplished from within PHP without having to rely on other scripting languages like JavaScript or VBScript? Also, anyone have any samples of PHP Event Handling code?
I am looking for something that allows me to do something like the following:
Example 2:
<img id=myimg name=myimg width="100" height="100" _&
onmousedown="myPHPScriptedEventHandler(myParameters)" _&
src="../images/example.gif" alt="clickable image">
Anyone had sucess with this sort of thing yet?
Thanx ahead of time for the assistance.
-Westmo
Is it possible to access the DOM for DHTML control with PHP?
Moderator: General Moderators
DOM and PHP are mutually exclusive. DOM is just the browser's document object model (client-side, whichever browser you use has a different DOM). PHP on the other hand is server-side.
I think trying what you are trying to do, although a good idea, is a bit like talking to a letter you receive to tell the sender something - it can't work.
I think trying what you are trying to do, although a good idea, is a bit like talking to a letter you receive to tell the sender something - it can't work.
PHP & DHTML using JScript/VBScript Includes
PatrikG,
I agree with you that things look mutually exclusive. I HAVE found that if you include client side JScript or VBScript code...
<?php
// Some php code to output headers, etc.
// below I start a <SCRIPT> tag in HTML then output all the data from the include file into the DHTML page.
printf(readfile(myincludefile.inc, 1))
// close up the <SCRIPT> tag and finish output of the rest of the page.
?>
** there may be some syntax issues here [this isn't exactly what I use but is close enough to get the point across - darn memory isn't what it used to be!!]
where the myincludefile.inc simply contains all the client side Java or VB Scripting you want. These functions can contain DOM functions, and can be referenced from within the client when the Events occur. This solves my problem, but creates another one.
When doing this, all my code for the manipulation of the page via DHTML is open to anyone who views the source of the page. This can be a security risk. Plus, code/source control goes right out the window when people can just copy your functions [only a problem if it ISN'T an Open Source Project anyway].
So, the crux of the problem seems to be that I can't use server side code for DHTML using PHP at all. This seems to be a drawback to PHP. Perhaps I am missing something obvious here?
Isn't it possible to use a standard ASP page with server side scripting to accomplish all the DHTML stuff you want without having to have client side scripting to do it? So how does the messaging get handled between the client & browser in that case? Exactly what is sent back & forth, and can it be captured & manipulated with PHP?
Eventually I will figure this out, but as always, help is appreciated.
-Westmo
I agree with you that things look mutually exclusive. I HAVE found that if you include client side JScript or VBScript code...
<?php
// Some php code to output headers, etc.
// below I start a <SCRIPT> tag in HTML then output all the data from the include file into the DHTML page.
printf(readfile(myincludefile.inc, 1))
// close up the <SCRIPT> tag and finish output of the rest of the page.
?>
** there may be some syntax issues here [this isn't exactly what I use but is close enough to get the point across - darn memory isn't what it used to be!!]
where the myincludefile.inc simply contains all the client side Java or VB Scripting you want. These functions can contain DOM functions, and can be referenced from within the client when the Events occur. This solves my problem, but creates another one.
When doing this, all my code for the manipulation of the page via DHTML is open to anyone who views the source of the page. This can be a security risk. Plus, code/source control goes right out the window when people can just copy your functions [only a problem if it ISN'T an Open Source Project anyway].
So, the crux of the problem seems to be that I can't use server side code for DHTML using PHP at all. This seems to be a drawback to PHP. Perhaps I am missing something obvious here?
Isn't it possible to use a standard ASP page with server side scripting to accomplish all the DHTML stuff you want without having to have client side scripting to do it? So how does the messaging get handled between the client & browser in that case? Exactly what is sent back & forth, and can it be captured & manipulated with PHP?
Eventually I will figure this out, but as always, help is appreciated.
-Westmo
-
fractalvibes
- Forum Contributor
- Posts: 335
- Joined: Thu Sep 26, 2002 6:14 pm
- Location: Waco, Texas
Using either ASP or PHP you could certainly write out the javscript dynamically and conditionaly if needed. Then it is just the html and javascript served up to the browser. Once served up to the client, the javascript is the only interface the DOM.
You can have more interactions via PHP, but requires posting back to the server and resending the page.
Phil J.
You can have more interactions via PHP, but requires posting back to the server and resending the page.
Phil J.
between requests there is no connection between clients and servers over http. As soon as a document (and maybe dependecies) is delievered you might shutdown your internet connection wihtout any harm.
Clientside scripting languages are the only interface to the clientside-DOM.
For a webserver (and the server-side scripts) all that has been delievered was just another datastream whatever it contained. What it might be is only an interpretation of the client
Clientside scripting languages are the only interface to the clientside-DOM.
For a webserver (and the server-side scripts) all that has been delievered was just another datastream whatever it contained. What it might be is only an interpretation of the client