Jump to content

Dynamic text edit


Seven_Rings

Recommended Posts

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.