Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to transform text to input? [closed]

How can I create something such as:
- there is some text
- I click on it
- It transforms into an input that contains the text I clicked on.

like image 578
Karlus Avatar asked Jul 02 '11 16:07

Karlus


2 Answers

How about something like this

HTML

<div onclick="transform(this)">Some text here</div>

Javascript

function transform(obj)
{
    obj.innerHTML = "<input type='text' value='" + obj.innerHTML + "' />";
}

Hope I've understood your question correctly.

like image 178
Ash Burlaczenko Avatar answered Sep 26 '22 07:09

Ash Burlaczenko


<a href="#" onclick="var input = document.createElement('input'); input.setAttribute('value', this.firstChild.nodeValue); this.parentNode.replaceChild(input, this);">here is some text</a>. Click it.

Instead of <a> you could also use <span> or <div> whatever you feel like.

like image 41
yankee Avatar answered Sep 25 '22 07:09

yankee