views:

41

answers:

2

I have an image button and when I click it I want an specific field to go from text to an editable textfield, kinda like a dynamic edit button.

So I have the plain text with certain id (ie. id="text1") and when I click the button, the text changes to an editable field, maybe something like $("#text1").hide(); and then $("#field1").show(); but in between I need to give the field the value of the text, and then when I click the button save I should hide the input field and just show the text with the new value.

Any help will be greatly appreciated.

Thanks :D

A: 

Not too bad. The text goes into the value area of the text field. So get it from the text area, save it in a temp variable, and put it in the textfield.

Actually, you don't even need the temp I don't think, it should look something like

$('#field1').val($('#text1').text)

Note this is untested. You might find this SO article to be of value as well.

Charlie Martin
@Charlie, `text()` is a method thus requiring `()`. Also the elements need to be hidden/shown when the button is clicked :)
Marko
"Note this is untested".
Charlie Martin
+3  A: 
Marko
I get the impression that the OP wants to change from a text-node (say a `p`) to a `textarea`, rather than from an `<input type="text" />`.
David Thomas
@David - You're right I completely misunderstood that. Have modified slightly to suit.
Marko
@Marko, so I saw. +1 for the edit, and the lorem ipsum from the *'hood* =)
David Thomas
@David - see my update for some crazy editable code :)
Marko
@Marko - the code is almost perfect, but I should be able to edit it multiple times, not just one time
fgualda87
also, I just noticed that the id changes, it should not change at all.
fgualda87
@fgualda87, I'll try find some time to edit the solution or create a plugin!
Marko