Click to See Complete Forum and Search --> : Update HTML table
dummyagain
July 29th, 2006, 12:53 PM
I made a table containing several rows and columns. Each cell contains a unit of information taken from the database. The rightmost columns of each row has a button "Edit". If the user click the button, the whole row should be able to be edited by the user. And the Edit Button will change to "Update" Button for the user to confirm the update.
However, I would like to know how to only make that row available to update but others are disabled for update?
Please advice.
Thank you
PeejAvery
July 29th, 2006, 04:46 PM
Well, since you are getting information from the server you will have to refresh.
There is one way around this but it can be somewhat annoying.
display.php
<html>
<body>
<iframe width=0 height=0 frameborder=0 name='theframe'></iframe>
<script language="JavaScript">
function dorename(id){
var fn = prompt('First name?', '');
var ln = prompt('Last name?', '');
theframe.location.replace('edit.php?id=' + id + "&fn=" + fn + "&ln=" + ln);
}
</script>
<table>
<?php
$sql = mysql_query("SELECT * FROM `person`");
while($info = mysql_fetch_assoc($sql)){
$fn = $info['firstname'];
$ln = $info['lastname'];
$id = $info['id'];
echo "
<tr>
<td><div id='fn$id'>$fn</div></td>
<td><div id='ln$id'>$ln</div></td>
<td><input type=\"button\" value=\"Rename\" onclick=\"dorename('$id')\"></td>
</tr>
";
}
?>
</table>
</body>
</html>
edit.php
<?php
$fn = $_GET['fn'];
$ln = $_GET['ln'];
$id = $_GET['id'];
if(mysql_query("UPDATE `person` SET `firstname` = '$fn', `lastname` = '$ln' WHERE `id` = '$id'")){
echo "
<script language='JavaScript'>
parent.document.getElementById('fn$id').innerHTML = '$fn';
parent.document.getElementById('ln$id').innerHTML = '$ln';
location.replace('about:blank');
</script>
";
}
?>
dummyagain
July 29th, 2006, 09:39 PM
Actually I am using ASP.NET and VB to write this page, I would like to can i do sth smilar (following your logic) to implement that?
Thanks
PeejAvery
July 29th, 2006, 11:27 PM
Actually I am using ASP.NET and VB to write this page, I would like to can i do sth smilar (following your logic) to implement that?
Oh, well you posted in the wrong forum then. I will have a moderator move it.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.