|
|
|
| Web Hosting Guide |
![]() ![]() |
Javascript: Text To Texbox And Back To Text |
Mar 5 2006, 10:04 PM
Post
#1
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 1 Joined: 5-March 06 Member No.: 11,759 |
i need some help i want to create a thing where when some one double clicks a certain text it changes into a texbox where they can edit the text and the they double click and it changes into the test they just typed in.
I have found this function in javascript that does some of it but i needs to be simplified CODE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Span to Text Box - Demo - DOM</title> <script type="text/javascript"> /* © John Davenport Scheuer */ function exchange(el){ var nodeI=el.parentNode, inputC=document.createElement('input'), text=el.innerHTML; el.style.font='.9em "ms sans serif", "sans"' el.innerHTML+='\x20' with (inputC){ setAttribute('value', text, 0) setAttribute('size', text.length-1, 0) style.width=document.all&&!window.opera? el.offsetWidth-2+'px' : el.offsetWidth+2+'px' setAttribute('type', 'text', 0) setAttribute('id', el.id, 0) } nodeI.replaceChild(inputC, el) } </script> </head> <body> <span id="itm1" onclick="exchange(this)">House</span><br> <span id="itm2" onclick="exchange(this)">SpantoTextBox-Demo</span><br> <span id="itm3" onclick="exchange(this)">Span to Text Box - Demo exchange(this)</span><br> <input id="itm4" type="text" value="Existing Text Box"><br> <span id="itm5" onclick="exchange(this)">In Line Test</span> <span id="itm6" onclick="exchange(this)">In Line Test Too</span> <span id="itm7" onclick="exchange(this)">In Line Test Also</span> </body> </html> If its possible to have it in php or javascript please This post has been edited by miCRoSCoPiC^eaRthLinG: Mar 6 2006, 08:07 AM |
|
|
|
Mar 8 2006, 12:44 AM
Post
#2
|
|
|
S.P.A.M.S.W.A.T. Group: Members Posts: 814 Joined: 22-January 05 Member No.: 2,284 |
I couldn't understand the code you've given, so I couldn't simplify it. Instead, I decided to code it from scratch. Here it is:
CODE <p id="text" onclick="change();">Hello, world. Click me please.</p> <form onsubmit="return false;"> <input type="hidden" id="textbox" /> <input type="hidden" id="done" onclick="changeBack();" value="Done"/> </form> <script type="text/javascript"> /*<![CDATA[*/ var textNode = document.getElementById('text'); var textValue = textNode.firstChild.nodeValue; var textboxNode = document.getElementById('textbox'); var doneButton = document.getElementById('done'); function change() { textboxNode.setAttribute('value', textValue); textNode.style.display = 'none'; textboxNode.setAttribute('type','text'); doneButton.setAttribute('type','button'); } function changeBack() { textNode.firstChild.nodeValue = textboxNode.value; textNode.style.display = 'block'; textboxNode.setAttribute('type', 'hidden'); doneButton.setAttribute('type','hidden'); } /*]]>*/ </script> This will do almost exactly what you wanted. At first, the only thing visible will the paragraph, which contains the text "Hello, world. Click me please.". When it is clicked, the paragraph will become invisible, and the hidden textbox will appear and take its place. Then, you can edit the textbox. I don't think double-clicking can be detected by Javascript, so I made a button that can be pressed when you are done editing. When the button is pressed, the textbox and button disappear and the paragraph reappears. That is basically how the whole script works. Now I'll explain what each of the lines do. HTML: The first line is the paragraph. The onclick attribute is used to trigger the JavaScript. The second line is the beginning of the form. The onsubmit attribute is used to stop the form from submitting, therefore reloading the page. Third and Fourth are the textbox and button. The type="hidden" attribute is to make them invisible. Again, onclick is used to trigger the JavaScript. And finally, the value attribute is to add the text to the button. java script: The first 4 lines store different nodes into variables for faster access. Here are what they store, respectively: the paragraph, the text inside the paragraph elememt, the textbox, the button. In the first function change(): In the first line, the textbox's text will be changed to the same as the paragraph's text. Then in the second line, the paragraph element is hidden from view. In the third, the textbox will change from a hidden input box to a textbox input box. In the fourth line, the button will change from a hidden input to a button input. In the second function changeBack(): In the first line, the paragraph's text is changed into what you entered in the textbox. In the second, the paragraph is set to display: block, which basically makes it visible. In the third and fourth line, the textbox and button are both set back to hidden inputs again. I hope you could understand this code. If you have any questions or if you want me to change the code, just reply and tell me. I didn't know what you mean by "to have it in PHP". PHP can't be used to do interactive things in your browser. |
|
|
|
Jan 7 2008, 11:27 AM
Post
#3
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 0 Joined: 1-November 07 Member No.: 25,869 |
I tried the same code but its not working
Javascript: Text To Texbox And Back To Text Hi All, The tried the same code but tis not working.Please assist me -jeena |
|
|
|
May 15 2009, 07:37 PM
Post
#4
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 0 Joined: 1-November 07 Member No.: 25,869 |
Showing/hidding a text display area
Javascript: Text To Texbox And Back To Text How can I write a button that whn pressed will show a text display area in a table cell saying let's say "HELLO" and, then, when pressed again it will cause the display area to disappear? By the same token, I'd like also to have a button that when pressed will display a picture in a table cell, and when pressed again the picture will disappear. Thanks! James |
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
7 | DRMremoval | 303 | 16th November 2009 - 09:35 AM Last post by: iMacapple |
|||
![]() |
5 | Curt200518 | 259 | 11th November 2009 - 06:29 PM Last post by: yordan |
|||
![]() |
1 | xboxrulz | 326 | 5th November 2009 - 08:29 PM Last post by: HannahI |
|||
![]() |
4 | rahid | 915 | 4th November 2009 - 12:27 AM Last post by: HannahI |
|||
![]() |
0 | HannahI | 24 | 3rd November 2009 - 09:43 PM Last post by: HannahI |
|||
![]() |
0 | Swisoon | 104 | 30th October 2009 - 02:18 PM Last post by: Swisoon |
|||
![]() |
6 | szupie | 2,768 | 30th October 2009 - 01:06 PM Last post by: Quatrux |
|||
![]() |
5 | starscream | 69 | 30th October 2009 - 07:31 AM Last post by: starscream |
|||
![]() |
17 | vdhieu84 | 6,888 | 29th October 2009 - 07:44 PM Last post by: iG- |
|||
![]() |
14 | Grafitti | 3,078 | 26th October 2009 - 06:34 AM Last post by: iG-Khalid Mehmood Awan |
|||
![]() |
2 | Miles | 740 | 12th October 2009 - 12:49 PM Last post by: iG-John Rivera |
|||
![]() |
10 | bob3695 | 8,270 | 12th October 2009 - 06:38 AM Last post by: iG-Sewe Oyaya |
|||
![]() |
2 | jedipi | 3,405 | 8th October 2009 - 08:47 AM Last post by: iG-Neville |
|||
![]() |
8 | kc8ual | 2,582 | 5th October 2009 - 08:56 PM Last post by: HannahI |
|||
![]() |
9 | dragoneye | 8,070 | 5th October 2009 - 09:15 AM Last post by: starscream |
|||
|
Lo-Fi Version | Time is now: 22nd November 2009 - 06:11 AM |
© 2009 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation



Mar 5 2006, 10:04 PM




