View Full Version : Replace HTML on event?

01-13-2010, 03:33 PM
Hello, I was wondering if it was possible to make a script which would allow me to click a button, then a php script would write some HTMK code using the echo function.

This HTML would be a div tag containing some text which will be pulled from a database. At the bottom of this div there would be a link which will make this div invisible so it is hidden/removed from the code.

This will allow a different button to be clicked, this would then load some new text from the database into the same div.

I understand that by using a php script which will write the div tag again using the echo function it would just write it again under the code written before. I do nopt want this as if there are hundred of buttons, then the code of the page will become large and may slow down the users computer.

Sorry for my bad gramma and punctuation in the first paragraph.

01-13-2010, 03:39 PM
It won't write it anywhere.
PHP is server side, so it cannot respond to events from the client. What you can do is look at using javascript through ajax to access the PHP page of choice if you need dynamic handling. If you're just writing html than you can just use javascript.

01-13-2010, 03:57 PM
I have been using this code so that the PHP will respond to a users actions... can I not do it like this?

// Insert data
if (isset($_POST['submit']))

01-13-2010, 04:36 PM
You need to combine javascript with php to get this done. Take a look at http://www.deathmonkeyz.com/tutorials/ for AJAX tutorials that should get the ball rolling for you

01-13-2010, 04:39 PM
Dammit, this means learning another coding language :(

That sucks because I havn't really got time to learn more languages. I will have a quick look though. Cheers :)

And I hate AJAX :(

01-13-2010, 04:51 PM
AJAX is very easy to learn to use for what you need, and shouldn't take more than 30 minutes to do so. You don't need to learn javascript, just how to implement the bit of code you need

01-13-2010, 10:26 PM
Oh right, cool :)

I didnt really want to wander too far into other languages as I am comfortable in PHP Lol.