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
Reply

Join Date: Mar 2005
Posts: 960
Reputation: belama is an unknown quantity at this point 
Solved Threads: 2
belama's Avatar
belama belama is offline Offline
Posting Shark

Add textbox to editable div problem

 
0
  #1
Apr 8th, 2005
I am having a problem with a javascript script.

Add this code to an html file if you wanna try it.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <script>
  4. var n = 0;
  5. function addtb(){
  6. document.getElementById('TextEditor').focus();
  7. cmd = 'InsertInputText';
  8. document.getElementById('TextEditor').document.execCommand(cmd,'true');
  9. document.getElementById('TextEditor').blur();
  10.  
  11.  
  12. var TE = document.getElementById('TextEditor');
  13. var TEcn=TE.children;
  14.  
  15. for (i=0;i<TEcn.length;i++)
  16. {
  17. n++;
  18. if(TEcn[i].id == "")
  19. TEcn[i].id = "tb" + n;
  20.  
  21. }
  22. }
  23. function tellids(){
  24. var TE = document.getElementById('TextEditor');
  25. var TEcn=TE.children;
  26.  
  27. for (i=0;i<TEcn.length;i++)
  28. {
  29. alert(TEcn[i].id);
  30.  
  31. }
  32. }
  33. </script>
  34. </head>
  35. <body bgcolor=dddddd>
  36. <div id="TextEditor" contenteditable="true" indicateeditable="true"
  37. style="BACKGROUND-COLOR:white;OVERFLOW: auto;WIDTH: 600px;HEIGHT: 500px;WORD-WRAP: break-word"></div>
  38. <input type=button onclick="addtb();" value="add a text box">
  39. <input type=button onclick="tellids();" value="alerts of textbox ids">
  40. <br>
  41.  
  42. 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.
  43. If you dont, you will have to doubleclick the button, and I dont want that.
  44. I would like the selected textbox to be blurred and then add another textbox with a single click of the button.
  45.  
  46. </body>
  47. </html>
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Add textbox to editable div problem

 
1
  #2
Apr 8th, 2005
You need to empty the current selection range.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function addtb()
  2. {
  3. document.selection.empty();
  4. document.getElementById("TextEditor").focus();
  5. cmd = 'InsertInputText';
  6. document.getElementById('TextEditor').document.execCommand(cmd,'true');
  7.  
  8. var TE = document.getElementById('TextEditor');
  9. var TEcn=TE.children;
  10.  
  11. for (i=0;i<TEcn.length;i++)
  12. {
  13. n++;
  14. if(TEcn[i].id == "")
  15. TEcn[i].id = "tb" + n;
  16. }
  17.  
  18. }
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 960
Reputation: belama is an unknown quantity at this point 
Solved Threads: 2
belama's Avatar
belama belama is offline Offline
Posting Shark

Re: Add textbox to editable div problem

 
0
  #3
Apr 8th, 2005
Thanks. So simple and it works.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC