473,412 Members | 4,594 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

set textarea value to iframe?

i am planning on kind of editor by replacing the textarea with iframe so that i could edit the content with rich html.

I am facing weird problem and i cannot set the value of iframe innerHTML with the value of textarea while loading. The idea is hide the textarea after moving the value to iframe rich text editor.

what could be the problem. here is the code

Expand|Select|Wrap|Line Numbers
  1.  
  2. var myeditor; 
  3.  
  4. window.onload = function() 
  5. myeditor = document.getElementById('rte').contentWindow.document; 
  6. myeditor.designMode = "on";
  7.  
  8. }
  9.  
  10. function Start(obj,width,height) {
  11.  
  12.  
  13.     document.write("<img src=\"bold.gif\" name=\"btnBold\" onClick=\"doClick('bold')\">"); 
  14.     document.write("<img src=\"italic.gif\" name=\"btnItalic\" onClick=\"doClick('italic')\">");
  15.     document.write("<img src=\"underline.gif\" name=\"btnUnderline\" onClick=\"doClick('underline')\">");
  16.     document.write("<img src=\"link.gif\" name=\"btnLink\" onClick=\"doLink()\">");
  17.     document.write("<img src=\"unlink.gif\" name=\"btnUnlink\" onClick=\"doClick('unlink')\">");
  18.     document.write("<img src=\"picture.gif\" name=\"btnPicture\" onClick=\"doImage()\">");
  19.     document.write("<br>");
  20.  
  21.     document.write("<iframe id=\"rte\" width=\"" + width + "\" height=\"" + height + "\" style=\"border:1px solid grey\"></iframe>");
  22.  
  23.  LoadData(obj);
  24. }
  25.  
  26. function LoadData(obj)
  27. {
  28.  
  29. myeditor.body.innerHTML= document.getElementById(obj).value;
  30. document.getElementById(obj).style.visibility="hidden";
  31. }
  32. [/html]
  33.  
  34. [html]
  35. <form action="" method="post" >
  36.   <p>
  37.  
  38.  <textarea name="mybox" id="mybox" >This is a <b>bold</b> sample textarea</textarea>
  39.  <script>Start('mybox',600,400);
  40.   </script>
  41.   </p>
  42.   <p>
  43.     <input type="submit" name="Submit" value="Submit">
  44.   </p>
  45. </form>
  46.  
Jul 29 '08 #1
2 3767
Hello,

Are you sure line #5 is OK? It says
Expand|Select|Wrap|Line Numbers
  1. myeditor = document.getElementById('rte').contentWindow.docum  ent;
There are a couple of spaces between docum and ent

And the other problem is that <script> tags are evaluated as they are read from the HTML file. Your first script sets a window.onload event but that doesn't trigger until after everything has been rendered. In your second paste, on line 5, you're calling the Start() function. This is executed before the window.onload event is triggered, because the JS parser works like this:

  1. define variable myeditor
  2. set the window.onload event
  3. define function Start
  4. define function LoadData
  5. call the Start function
  6. execute window.onload
What you need to so is to put the call to Start() in the window.onload event. Normally you'd have a fixed window.onload function that calls the functions in an array and you'd have another function that adds functions to that array, something like this (not sure if this exact piece of code will work, but you get the idea):
Expand|Select|Wrap|Line Numbers
  1. var load_events = [];
  2. window.onload = function () { for (var i = 0; i < load_events.length; ++i) load_events[ i ](); }
  3. function addLoadEvent(func) { load_events[load_events.length] = func; }
  4.  
  5.  
  6. // ... later ...
  7. function init_myeditor()
  8. {
  9. myeditor = document.getElementById('rte').contentWindow.document;
  10. myeditor.designMode = "on"
  11. }
  12. addLoadEvent(init_myeditor); // no () because we pass the function, not it's result
  13.  
  14.  
  15. // ... later ...
  16. addLoadEvent(function () { Start('mybox', 600, 300); });
This would cause the init_myeditor() function to trigger before the anonymous function that calls Start() and, best of all, it will allow you to add other onload events. All you need to do is make sure that you add them in the right order.

Regards,
Tom
Jul 30 '08 #2
i have a problem creating rich text editor .how to call two different function in iframe?
Jul 12 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: delraydog | last post by:
I'm trying to make either an IFrame or a DIV look 'exactly' like a textarea. The problem I've run into with IFrames is not being able to replace the 3D recessed border with a single pixel border....
5
by: David | last post by:
Hey, I'm not quite sure where to post this, but I believe this is the most appropriate place. I have a page I am creating that does a submission within a hidden IFRAME every time someone adds...
5
by: sunadumari | last post by:
Hi folks, hope I'm in the wright section (I'm a newbie). I've got a textarea that, with the click on a button, shows the html-look of the data in the textarea. This script I found on the net (with...
4
by: empiresolutions | last post by:
I need to show PHP and HTML code inside of a textarea for people to copy out into their own site. I can get code to work correct without PHP code in it like htmlspecialchars("<iframe src...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.