View Single Post
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