473,805 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

accessing DOM

I want to access the DOM. Can something like this be done with PHP or a
combination of PHP/JAVASCRIPT? not tested!
<html><head><ti tle>DOM test</title>
<?php
$inFileName = 'test.js';
$outFileName = 'jk.js';
function doIt() {
$dd = getElementById( 'first');
$dd.innerText=$ outFileName;
}
?>
</head>
<body>
<p id="first" onclick="doIt() ">ClickMe<b r>
<p onclick="first. innerText=$inFi leName">ClickMe <br>
</body></html>
Jul 17 '05 #1
6 2307
"J. J. Cale" <ph****@netvisi on.net.il> wrote:
I want to access the DOM. Can something like this be done with PHP or a
combination of PHP/JAVASCRIPT? not tested!
<html><head><ti tle>DOM test</title>
<?php
$inFileName = 'test.js';
$outFileName = 'jk.js';
function doIt() {
$dd = getElementById( 'first');
$dd.innerText=$ outFileName;
}
?>
</head>
<body>
<p id="first" onclick="doIt() ">ClickMe<b r>
<p onclick="first. innerText=$inFi leName">ClickMe <br>
</body></html>


Of course you can do it, you just have to assure the PHP code will not be
parsed by your server and you have to find a browser which allows PHP, in
extension to javascript, as client side scripting language.

OTOH, if you want the client side javascript to call a server side PHP
function, you have to generate a completely new HTTP-Request using
document.locati on= or similar, resulting in a *completely* new page or in
*no* new page (for example HTTP 204: No Content).
If you want to *modify* the current page from within PHP using PHP on
javascript variables that cleary shows you didn't understand the concept of
a server side script language.
--
Simon Stienen <http://dangerouscat.ne t> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #2
[original snipped]
If you want to *modify* the current page from within PHP using PHP on
javascript variables that cleary shows you didn't understand the concept
of
a server side script language.


With all due respect, this is of course, entirely possible. Perhaps before
you say that people do not understand, you should first make sure that you
understand it perfectly.

On first blush, you would seem correct: JavaScript is client side, PHP is
server side, and never the two shall mix. Yes, of course, you can use PHP to
write JavaScript as the page is rendered, and yes of course, this works
well.

But, think about this... place an inline frame (hidden) on the page to
modify the JavaScript variables from. Someone on your page is something that
the user does (presumably; perhaps they select an item from a drop down
list) that should cause a change. To make this happen, add a JavaScript
function that replaces the URL of the inline frame. The new URL loads a PHP
page which presumably does something (perhaps it gets data from a database).
As the page finishes, it writes a JavaScript function that calls back to the
opening page (the opener. syntax) and executes a function there; this
function can now happily change variables in JavaScript (because it IS
JavaScript). PHP can change JavaScript.

I will grant you it is not a straightforward approach. I will also tell you
that Apple has documented it quite well, and I have used it in production
for over two years without a hitch. In my experience (a nice way to say
things), this is a stable, reliable solution.

OK. Just my two cents.

david
Jul 17 '05 #3
david <so*****@micros oft.com> wrote:
[original snipped]
If you want to *modify* the current page from within PHP using PHP on
javascript variables that cleary shows you didn't understand the concept
of
a server side script language.
With all due respect, this is of course, entirely possible. Perhaps before
you say that people do not understand, you should first make sure that you
understand it perfectly.


Well... Maybe you have information I didn't know...
On first blush, you would seem correct: JavaScript is client side, PHP is
server side, and never the two shall mix. Yes, of course, you can use PHP to
write JavaScript as the page is rendered, and yes of course, this works
well.
That's how far I was in the statement.
But, think about this... place an inline frame (hidden) on the page to
modify the JavaScript variables from. Someone on your page is something that
the user does (presumably; perhaps they select an item from a drop down
list) that should cause a change. To make this happen, add a JavaScript
function that replaces the URL of the inline frame. The new URL loads a PHP
page which presumably does something (perhaps it gets data from a database).
As the page finishes, it writes a JavaScript function that calls back to the
opening page (the opener. syntax) and executes a function there; this
function can now happily change variables in JavaScript (because it IS
JavaScript). PHP can change JavaScript.


Ok, so far... But: It's not the PHP changing the JavaScript but the
JavaScript which was written by the PHP in the inline frame, sounds like
hair-splitting, but it *is* a difference. Further, you are not modifying
the *current* page (which is the one in the iframe and completely
reloaded), but the parent page which contains the iframe.

I know this seems obvious, but if you take the small technical details,
you'll see, that my previous posting perfectly matches your case, too.
--
Simon Stienen <http://dangerouscat.ne t> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #4
Simon:
Well... Maybe you have information I didn't know...
I didn't know this either until I stumbled across one fine day. <grin>
Ok, so far... But: It's not the PHP changing the JavaScript but the
JavaScript which was written by the PHP in the inline frame, sounds like
hair-splitting, but it *is* a difference. Further, you are not modifying
the *current* page (which is the one in the iframe and completely
reloaded), but the parent page which contains the iframe.

I know this seems obvious, but if you take the small technical details,
you'll see, that my previous posting perfectly matches your case, too.


I have no wish to split hairs, and you are correct as well.

To me, it seemed the OP wanted the ability to affect JavaScript from PHP
(again, presumably because they are digging information out of a database or
other backend system/process, which I do not know how to do with just
JavaScript.); what I was suggesting does just that. The end result is that
PHP, um, adjusts JavaScript. It is just in a rather odd roundabout way. But,
I think the important thing is that the end user does not seem all the
backend stuff, and at the end of the day, that is the most important thing:
usability and a friendly page.

OK. Thanks for a good reply, Simon! I hope you have a most excellent day! (I
like it when everyone is right!)
david

Jul 17 '05 #5
> OTOH, if you want the client side javascript to call a server side PHP
function, you have to generate a completely new HTTP-Request using
document.locati on= or similar, resulting in a *completely* new page or in
*no* new page (for example HTTP 204: No Content).
If you want to *modify* the current page from within PHP using PHP on
javascript variables that cleary shows you didn't understand the concept of a server side script language.


You can actually do that in ASP.NET. You can attach server-side functions to
client-side events. You can also modify the document via the DOM on the
server-side.
Jul 17 '05 #6
On Sat, 25 Sep 2004 09:16:16 +0200, J. J. Cale wrote:
I want to access the DOM. Can something like this be done with PHP or a
combination of PHP/JAVASCRIPT? not tested!
<html><head><ti tle>DOM test</title>
<?php
$inFileName = 'test.js';
$outFileName = 'jk.js';
function doIt() {
$dd = getElementById( 'first');
$dd.innerText=$ outFileName;
}
?>
</head>
<body>
<p id="first" onclick="doIt() ">ClickMe<b r>
<p onclick="first. innerText=$inFi leName">ClickMe <br>
</body></html>


DOM is a standards-defined XML API, not a Javascript feature. Many of
languages have DOM support, including PHP.

Be aware, however, that DOM support in PHP4 is not very good; I strongly
suggest to use PHP5 to use DOM, if possible.

Berislav
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4247
by: Amy Tseng | last post by:
Hi, I am having a problem accessing SQL Server 2000 via UNIX. I am accessing SQL Server 2000 from Solaris using Sybase Open Client (CT-Lib). Here is the error message: CT-LIBRARY error: ct_connect(): network packet layer: internal net library error: Net-Library operation terminated due to disconnect
5
2419
by: Sandeep | last post by:
Hi, In the following code, I wonder how a private member of the class is being accessed. The code compiles well in Visual Studio 6.0. class Sample { private: int x; public:
6
2749
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is called "form1", and I have selects called "PORTA", "PORTB" ... etc...
3
4322
by: prodirect | last post by:
Hi all, I hope someone can help me. I've recently created a database and wanted to put it up on an ftp sight so that multiple people could access the same tables at the same time from different geographical locations. I have been completely unsucessful in acheiving this goal so far however. Things I have tried: Create a shortcut to ftp sight via browser then tried to map local drive to
47
5297
by: fb | last post by:
Hi Everyone. Thanks for the help with the qudratic equation problem...I didn't think about actually doing the math...whoops. Anyway... I'm having some trouble getting the following program to work. I want to output a bit pattern from base 10 input. All I get is a zero after the input...I've looked over the code but can't see the problem...any ideas? /* display the bit pattern corresponding to a signed decimal integer */
3
3349
by: AdamM | last post by:
Hi all, When I run my VbScript, I get the error: "ActiveX component can't create object: 'getobject'. Error 800A01AD". Any ideas what I did wrong? Here's my VBScript: dim o set o=getobject(,"ConsoleApplication2.Program") msgbox o.TestString
1
3963
by: Eirik Brattbakk | last post by:
Hi I have some problems accessing a soap service made in c# using an ATL/MFC client over SSL. I have tried both CSoapMSXMLInetClient and CSoapWininetClient as template arguments with my stub class. The service is returning with the error code: -2147467259. I have not succeeded to find any additional information about the error. The "SoapFault" method seems to return only a bunch of question marks.
1
3142
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created elements and would like to seek a solution for this. I had looked through several articles for accessing programatically-created dynamic elements such as: 1)
3
1351
by: niju | last post by:
Hi there, I have three web pages (A,B,C). I need to prevent users accessing page B and C without accessing A. What would be the best way to achieve this rule? Many Thanks Niju
5
3070
by: Daniel Corbett | last post by:
I am trying to save a file dynamically created in a webpage. I get the following headers, but cannot figure out how to save the attachment. I am basically trying to replicate what internet explorer would do in this case. The headers I am getting are: Headers {Content-Disposition: attachment; filename="dynamic_file.mdb" Connection: close Cache-Control: private Content-Type: application/octet-stream
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10359
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7645
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5541
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.