Converting from Output to Input !

12-22-07, 11:11 AM
|
 |
Wannabe Coder
|
|
Join Date: Oct 2007
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Converting from Output to Input !
i want to edit a table but in the same page
when i click on Edit,the output value converts to input to be able to edit it
but i dont know why it didnt work????????
do u think it needs Ajax???
this is my code
|

12-28-07, 12:23 PM
|
|
Wannabe Coder
|
|
Join Date: Sep 2005
Location: Russia
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
First, you have no form to make submit work.
Second, strongly reccomend to use
to make more readable code.
Third, you do not need form neither AJAX here at all. Just use something form JavaScript stuff like:
Did not checked code, so not sure that one really works.
Good luck!
|

12-30-07, 06:09 AM
|
 |
Community Liaison
|
|
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
|
|
Quote:
Originally Posted by Wolf1994
Third, you do not need form neither AJAX here at all.
|
Actually you do if you want to save the edited data, unless you want to submit the form (causing the page to refresh).
The javascript code Wolf1994 posted will work, but it will not display the actual content in the div, here's one that should do the trick:
Javascript Code:
function setEditable (id) { var object = document.getElementById(id); var content = object.innerHTML; object.innerHTML = '<textarea rows="10" cols="50">' + content + '</textarea>'; }
In your html, you'll have to place this:
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks
|

12-30-07, 07:30 AM
|
 |
Level II Curmudgeon
|
|
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
|
|
Okay, I'm dense. How would you set that back to non-editable after editing?
|

12-30-07, 10:16 AM
|
 |
Community Liaison
|
|
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
|
|
Using the onblur event of the textarea, or either by adding a "save" button, like so:
Javascript Code:
function setEditable (id) { var object = document.getElementById(id); var content = object.innerHTML; object.innerHTML = '<textarea rows="10" cols="50" onblur="setNonEditable(' + id + ', this)">' + content + '</textarea>'; } function setNonEditable (div_id, textarea) { var object = document.getElementById(div_id); object.innerHTML = textarea.value; }
and the html:
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks
|

12-30-07, 12:24 PM
|
 |
Level II Curmudgeon
|
|
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
|
|
Cool. I'll learn something new every day if I'm not careful.
I had to give the text area an id and modify the save button a little bit to make it work right for me:
<button type="button" name="edit" onclick="setNonEditable('the_div', the_textarea)">Save</button>
Thanks Ed!
|

01-03-08, 02:50 AM
|
 |
Wannabe Coder
|
|
Join Date: Oct 2007
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well,frankly i didnt get it
this is my code
and i got in my page a table containing the data and a submit button called edit and i click on it the page changes to a text area containing that:
i dont understand!!
|

01-03-08, 02:51 AM
|
 |
Wannabe Coder
|
|
Join Date: Oct 2007
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
btw,my value in the table are
Web design
Web develop
maha
web
web
maha
|

05-05-08, 02:17 PM
|
|
Newbie Coder
|
|
Join Date: May 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I couldn't seem to get this working, I'll post what I had and hopefully somebody will see a mistake made.
here is the javascript file
Javascript Code:
function setEditable (id) { var object = document.getElementById(id); var content = object.innerHTML; object.innerHTML = '<textarea id="save" rows="10" cols="50" onblur="setNonEditable(' + id + ', this)">' + content + '</textarea>'; } function setNonEditable (div_id, textarea) { var object = document.getElementById(div_id); object.innerHTML = textarea.value; }
Last edited by UnrealEd; 05-06-08 at 02:53 AM.
Reason: proper syntax highlighting
|

05-06-08, 02:58 AM
|
 |
Community Liaison
|
|
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
|
|
This time I tested the code, and it all works fine in FireFox:
Javascript Code:
function setEditable (id) { var object = document.getElementById(id); var content = object.innerHTML; object.innerHTML = '<textarea id="save" rows="10" cols="50" onblur="setNonEditable(\'' + id + '\', \'save\')">' + content + '</textarea>'; } function setNonEditable (div_id, textarea) { try { var object = document.getElementById(div_id); object.innerHTML = document.getElementById(textarea).value; } catch (e) {} }
And the HTML:
Enjoy!
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|