Hello,
I am creating a feature for a site, that when you click a button changes specified text to a textbox that lets you edit the text. When the user presses enter, the textbox will dissapear and the text typed will be in it's place. This is so I don't have to a PHP script a bunch of times. The Javascript uses AJAX to submit that data and the page doesn't refresh. My problem is with the second step. The text will change to the textbox, but the onKeyPress teg is not displaying right. It should look like this:
onKeyUp="SDcheck(event, 'test', this)"
Yet it actually looks like this:
onKeyUp="SDcheck(event, " value=test")"
Here is my code:
<script type="text/javascript">
function EditBox(box, box2)
{
var textP = document.getElementById(box);
var text = textP.innerHTML;
textP.innerHTML = "<input type=\'text\' value=\'"+text+"\' id=\'"+box2+"B\' onKeyPress=\'SDcheck(event,\'"+box2+"\',this)\' />"
document.getElementById(box+'B').focus();
}
function SDcheck(even, id, element)
{
var characterCode;
if(e && e.which){
e = e;
characterCode = e.which;
}
else{
e = event;
characterCode = e.keyCode;
}
if(characterCode == 13){
var text = element.value;
document.getElementById(id).innerHTML = text;
return false;
}
else{
return true
}
}
</script>
<span id="test">Test</span> <a href="javascript:EditBox('test');">Edit</a>
Please Help me correct this problem!!!
Thanks!!