开发者

Edit in place with javascript and update the array value?

I am not using any javascript plugin,

<html>
<head>
<title>sample dynamic select list</title>
<script language='javascript'>
function changeContent(tablecell)
{
    tablecell.innerHTML = "<INPUT type=text name=newname onBlur=\"javascript:submitNewName(this);\" value=\""+tablecell.innerHTML+"\">";
    tablecell.firstChild.focus();
}
function submitNewName(textfield)
{

    textfield.parentNode.innerHTML= textfield.value;
}
</script>
</head>
<?php
$exrate = array("USD"=>array('sale'=>123,"buy"=>456))
?>
<body>
Double click on any cel开发者_JS百科l. Then enter your own text and then tab out or click on other place.
<table border=1 bgcolor=gray>
<tr>
<th>Currency</th>
<th>Buy</th>
<th>Sale</th>
</tr>
<tr>
<td>USD</td>
<td onDblClick="javascript:changeContent(this);"><?=$exrate["USD"]["sale"]?></td>
<td onDblClick="javascript:changeContent(this);"><?=$exrate["USD"]["buy"]?></td>
</tr>
</table>
</body>
</html> 

When Double click on any cell Then enter your own text and then tab out or click on other place.so How can I update these data example store in an array ,can store values in every time edited?


You need to first persist these values server-side somehow (how is $exrate being stored? is it in the session, database, etc?) and then you could bind an even on the tablecell's blur event and make an ajax request to update the values in your server-side store.

That said, with so many easy to use and lightweight javascript frameworks/libraries out there I don't see why you would want to do this manually (except maybe as a learning exercise or an innovative form of self-flagelation).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜