Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post

    Exclamation Replace HTML on event?

    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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    I have been using this code so that the PHP will respond to a users actions... can I not do it like this?

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

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    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
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #5
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    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

  • #6
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    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
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #7
    Regular Coder
    Join Date
    Nov 2007
    Posts
    680
    Thanks
    319
    Thanked 1 Time in 1 Post
    Oh right, cool

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •