| | |
Add textbox to editable div problem
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
I am having a problem with a javascript script.
Add this code to an html file if you wanna try it.
After you add your first textbox to the editor, you need to unselect it to be able to add another textbox with only one click of the button.
If you dont, you will have to doubleclick the button, and I dont want that.
I would like the selected textbox to be blurred and then add another textbox with a single click of the button.
If anyone could help, I would really appreciate it.
thx
Add this code to an html file if you wanna try it.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<html> <head> <script> var n = 0; function addtb(){ document.getElementById('TextEditor').focus(); cmd = 'InsertInputText'; document.getElementById('TextEditor').document.execCommand(cmd,'true'); document.getElementById('TextEditor').blur(); var TE = document.getElementById('TextEditor'); var TEcn=TE.children; for (i=0;i<TEcn.length;i++) { n++; if(TEcn[i].id == "") TEcn[i].id = "tb" + n; } } function tellids(){ var TE = document.getElementById('TextEditor'); var TEcn=TE.children; for (i=0;i<TEcn.length;i++) { alert(TEcn[i].id); } } </script> </head> <body bgcolor=dddddd> <div id="TextEditor" contenteditable="true" indicateeditable="true" style="BACKGROUND-COLOR:white;OVERFLOW: auto;WIDTH: 600px;HEIGHT: 500px;WORD-WRAP: break-word"></div> <input type=button onclick="addtb();" value="add a text box"> <input type=button onclick="tellids();" value="alerts of textbox ids"> <br> After you add your first textbox to the editor, you need to unselect it to be able to add another textbox with only one click of the button. If you dont, you will have to doubleclick the button, and I dont want that. I would like the selected textbox to be blurred and then add another textbox with a single click of the button. </body> </html>
If you dont, you will have to doubleclick the button, and I dont want that.
I would like the selected textbox to be blurred and then add another textbox with a single click of the button.
If anyone could help, I would really appreciate it.
thx
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
You need to empty the current selection range.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function addtb() { document.selection.empty(); document.getElementById("TextEditor").focus(); cmd = 'InsertInputText'; document.getElementById('TextEditor').document.execCommand(cmd,'true'); var TE = document.getElementById('TextEditor'); var TEcn=TE.children; for (i=0;i<TEcn.length;i++) { n++; if(TEcn[i].id == "") TEcn[i].id = "tb" + n; } }
![]() |
Similar Threads
- separating line by line from textbox with textmode=multiline (ASP.NET)
- Have a problem with centering "jpg" files (HTML and CSS)
- retrieving ids from dynamically created controls in asp.net (ASP)
- Ideas for final year multimedia project (IT Professionals' Lounge)
- more problem!!!! (Windows Software)
- Win98 Shutdown problem (Windows 95 / 98 / Me)
- XFX mobo -> cd drive connectivity problem (Motherboards, CPUs and RAM)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Making web site fill browser screen
- Next Thread: Sort Tables...
Views: 19256 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxexample ajaxhelp ajaxjspservlets array automatically autoplay beta blackjack boarder box button captcha card cart codes column css date debugger decimal design developer dom download element embed enter error events firefox flash focus form frameworks gears getselection google gwt hiddenvalue hint html htmlform ie7 iframe index java javascript javascripthelp2020 javascripts jawascriptruntimeerror jquery jsp libcurl listbox maps marquee masterpage media menu microsoft mimic mp4 offline onerror onmouseover parameters paypal php player position post problem programming prototype rating redirect safari scale scriptlets search security select size software sources starrating toggle tweet unicode validation variables w3c web webkit webservice window windowofwords xml






