modifying client side elements from server side php

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
sales@gmba.dk
Forum Newbie
Posts: 2
Joined: Sun May 11, 2008 12:25 pm

modifying client side elements from server side php

Post by sales@gmba.dk »

Hi, I am fairly new to php, javascript and html, but I have got a lot of stuff working by looking at other people examples and extrapolating from that.
I have created a number of html pages (by help of a design editor) and would just like to add php-serverside code to retrieve some data and perform some logic. I am almost there...
What I cannot get working is having my server side php code modify some elements from the caller html page.
In javascript I can use getElementById and then change innerHTML.
In my php function I can't seem to make that work.

In the writeup below I would like the element "thiselement" to have the text "goodbuy" when the link is clicked on.

HTML:

...
<a id=thiselement>hallo</a>
..
<a href=..function.php>call php</a>

and in another file:
function.php:

...
function modElement() {
$el= $doc.getElementById('thiselement');
$el.innerHTML ='goodbuy';
}

The design is probably all wrong as I have tried imitating javascript, but could someone please advice me how to do this properly. And if possible not refer to ajax or another programming environment, it should be possible within plain old php right?

Thanks in advance
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: modifying client side elements from server side php

Post by califdon »

I would like the element "thiselement" to have the text "goodbuy" when the link is clicked on.
Right there is your problem of understanding. PHP is a server technology, working with Apache web server. By the time the browser receives the page, PHP is no longer in the picture at all. There is no possibility that it can detect a user's actions. Thus, you have to handle all user interaction (that is, everything that occurs after the browser displays the page) in Javascript. You can use Javascript to send another request to the server, such as is done with Ajax, and have PHP respond to that new request, but PHP can never do anything on its own to respond to a user action.
sales@gmba.dk
Forum Newbie
Posts: 2
Joined: Sun May 11, 2008 12:25 pm

Re: modifying client side elements from server side php

Post by sales@gmba.dk »

Thank you. Thats what you get from copying around instead of making the effort of really learning the stuff.
Thanks your reply saved me from many hours of trial and error.
Post Reply