Steps to make an in place editing in HTML using Javascript

1) Create div container where you want in place editing

2) Give it some id. eg
<div id=”d”> Here is the text that will get changed to input field</div>

3) Onclick of div call javascript function which will hold the innerHTML value of div.
<div id=”d” onclick=”edit();”> Here is the text that will get changed to input field</div>

4) form a string to print the input field in function
var textValue = ‘<input type=”text” id=”editedValue” value=”‘+ innerHTML +'” onblur=”save()”>’

5) Onblur of input field, get the values entered in textField.
var editedValue = document.getElementById(“editedValue”).innerHTML;

6) Assign it back the the original container
document.getElementById(“d”).innerHTML = editedValue;

Your in place editing is ready, fancy stuff

Pseudo Code

//call edit on click of div
function edit()
{
var textValue = document.getElementById(“d”).innerHTML;
document.getElementById(“d”).innerHTML='<input type=”text” id=”
editedValue” value=’+'” ‘+textValue+'”>’;
}

//call save on blur of textField
function save()
{
var
editedValue = document.getElementById(“editedValue“).value;
document.getElementById(“d”).innerHTML=
editedValue;
}

I will put the working sample tomorrow.

Advertisements

One Response to Steps to make an in place editing in HTML using Javascript

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: