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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change to text box when click

    Hello, I want to make a simple databse editor. I want it so when you load the page it echos a certain cell. When you click on the cell I want that to disappear and a text input shows up with the echo'd information in it so you can edit it. any ideas on how i could do that?

    This is my current code:

    Code:
    <?php
    $link = mysql_connect("host", "user", "pass");
    mysql_select_db("db");
    $data = mysql_query("SELECT * FROM News ") or die(mysql_error());
    while ($info = mysql_fetch_array($data)) {
    $news = $info['News'];
    }
    Print "</table>";
    mysql_close($link);
    ?>
    <form method="post" action="newsedit.php">
    <textarea name="edit" cols="30" rows="10"><?php echo $news; ?></textarea>
    <input type="submit" value="Edit News" />
    </form>
    That would make the textbox to edit it, but when the page loads I just simply want to echo the news table (which I can do) but I have no idea how to make it so when I click on the text it turns into that textbox I have made up there. I'm hopefully assuming this involves javascript but I'm not entirely sure.

  • #2
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually, I just found this post: http://stackoverflow.com/questions/2...hen-i-click-it and the top answer explains this perfectly, but this makes it so any div can do this. Can I set it so only a div with the id "editable" will execute that code?

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,691
    Thanks
    25
    Thanked 656 Times in 655 Posts
    I think
    Code:
    var divHtml = $(this).html(); // notice "this" instead of a specific #myDiv
    change to

    Code:
    var divHtml = $("#editable").html();
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

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