Seven_Rings Posted October 19, 2008 Share Posted October 19, 2008 Hey. I am back with another problem I can't seem to solve. I have a table. <table> <tr> <td>Hello</td> <td>Goodbye</td> </tr> </table> I have a button <input value="Edit" /> How do I make it so that when I press "edit", the feilds in the table turn into text input, like this... <table> <tr> <td><input type="text" value="Hello" size="8"></td> <td><input type="text" value="Goodbye" size="8"></td> </tr> </table> Basicly, its an edit, I want to be able to submit that to my database. But I already know how to do that, the problem right now is changing the values to Text Inputs. Thanks in advance, -Seven_Rings Quote Link to comment Share on other sites More sharing options...
trq Posted October 19, 2008 Share Posted October 19, 2008 That would be Javascript. Quote Link to comment Share on other sites More sharing options...
Seven_Rings Posted October 19, 2008 Author Share Posted October 19, 2008 Oh, I thought there was a way to do it in PHP. I'm sorry Anyone here know how to do it? Thanks again, -Seven_Rings Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 19, 2008 Share Posted October 19, 2008 Yes, javascript. Do some googling for 'edit in place'. Quote Link to comment Share on other sites More sharing options...
Seven_Rings Posted October 19, 2008 Author Share Posted October 19, 2008 Thanks, I really appreciate it. *Not quite solved yet*, -Seven_Rings Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 19, 2008 Share Posted October 19, 2008 Oh, I thought there was a way to do it in PHP. I'm sorry Anyone here know how to do it? Thanks again, -Seven_Rings Are your 'hello' and 'goodbye' values coming from a database or are they hard coded in HTML? Quote Link to comment Share on other sites More sharing options...
Seven_Rings Posted October 19, 2008 Author Share Posted October 19, 2008 Theoretically, they are coming from a database. The goal would be to update the database. Thanks, -Seven_Rings Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 19, 2008 Share Posted October 19, 2008 Then you could just run a query against your database and parse the results into your form. <table> <tr> <td><input type="text" value="<?php echo $row['welcome_text']; ?>" size="8"></td> <td><input type="text" value="<?php echo $row['goodbye_text']; ?>" size="8"></td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Seven_Rings Posted October 19, 2008 Author Share Posted October 19, 2008 But it needs to look like a normal table cell until I give the command to edit it, at which time it would change to an editable field, and when submitted (user presses button, clicks off), an update query is run. -Seven_Rings Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 19, 2008 Share Posted October 19, 2008 So have it normal, if the user clicks the edit button it generates the query and creates the new table with a form in it using the retrieved values. This can be done with php, although it will take longer and have more code. It really would be easiest to use 'edit in place' javascript as the changes could be done in the client browser and not require the server. Quote Link to comment Share on other sites More sharing options...
Seven_Rings Posted October 19, 2008 Author Share Posted October 19, 2008 Yea, I think I found what I need. It may take some time to adopt only one of the examples, but I think I can use a watered down version of http://tool-man.org/examples/edit-in-place.html Thanks for the help, I may be coming back here for more help. I really appreciate you guys -Seven_Rings Quote Link to comment Share on other sites More sharing options...
thebadbad Posted October 19, 2008 Share Posted October 19, 2008 A PHP example: edit.php <?php //keys are form field names; values are form field values $values = array('name' => 'Joe', 'age' => '12'); if (isset($_GET['edit'])) { echo '<form action="process_file.php" method="post"> <table> <tr> '; foreach ($values as $name => $val) { echo "<td><input type=\"text\" name=\"$name\" value=\"", htmlentities($val), "\" /></td>\n"; } echo "</tr>\n</table><input type=\"submit\" />"; } else { echo "<table>\n<tr>\n"; foreach ($values as $val) { echo "<td>", htmlentities($val), "</td>\n"; } echo "</tr>\n</table><a href=\"edit.php?edit\">Edit</a>"; } ?> Quote Link to comment Share on other sites More sharing options...
Seven_Rings Posted October 19, 2008 Author Share Posted October 19, 2008 thebadbad, Seeing as how I don't really want to use JavaScript in this particular project, your post is very helpful. I think I could edit it to work, and if not, I have always got JavaScript Thanks for the help everyone, -Seven_Rings Quote Link to comment Share on other sites More sharing options...
Seven_Rings Posted October 19, 2008 Author Share Posted October 19, 2008 I'm not able to get anywhere with this. I cant seem to implement the JavaScript "edit_in_place" Here is what I am working on... http://www.thesevenrings.com/skillcomp/index.php I need to be able to edit the fields in the table with either "edit_in_place" or PHP (badbad's example) Can anyone help me? *It would take a lot of changing stuff to post my actual code* Thanks, -Seven_Rings Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.