0

I want to create a link where if the user presses the Edit link, the text will turn into a text box with the information still in what the user inputted? I have the following code: ( when i press the edit button the 'Text here' should turn into a textbox, but it doesn't could someone help notify where my code has gone wrong :) help would be appreciated.

<html> <head> <title>Span to Text Box - Demo</title> <style type="text/css"> .replace { display:none; } </style> <script type="text/javascript"> function exchange(id){ var ie=document.all&&!window.opera? document.all : 0 var frmObj=ie? ie[id] : document.getElementById(id) var toObj=ie? ie[id+'b'] : document.getElementById(id+'b') toObj.style.width=frmObj.offsetWidth+7+'px' frmObj.style.display='none'; toObj.style.display='inline'; toObj.value=frmObj.innerHTML } </script> </head> <body> <p class="edit" onclick="exchange(item)">Edit</p><Input id="item" class="replace" type="text" value=""> <span id="item" >Text here</span> </body> </html> 

2 Answers 2

1

you are assigning one id to two tag, from your code, I assume the id of input tag should be itemb

Sign up to request clarification or add additional context in comments.

6 Comments

if i rename the input should it work, because i just want it so that when the user presses edit the text in 'Text here' changes to a textbox with the 'Text here' still there so that they can edit?
On my website I have text in which has been sent from the database to display in posts, in order for the user to edit there post there is an edit button in which once they select the text will turn into a textbox, so text to the textbox in which they can make alterations to there text and once they have made changes there will be an update button which will update there text from what they have just entered to the database.
the tag with id itemb is not found. it certainly cannot work
This piece of code works, how would I change this so it was on click on <p>'Edit'</p> rather then the text itself. <span id="itm1" onclick="exchange(this.id)">House</span><input id="itm1b" class="replace" type="text" value="">
Sorry about that, done it now, thanks for the help :)
|
0

Your <input> and <span> have the same id

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.