473,804 Members | 3,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

set textarea value to iframe?

26 New Member
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 3808
rohypnol
54 New Member
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
mushrefa
2 New Member
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
5262
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. I've illustrated a textarea and an IFrame in the HTML sample below which shows my problem. I am willing to use a DIV but I do need the ability to change the contents of the DIV using innerHTML as well. Any suggestions? I've tried border="1",...
5
5724
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 an item to the shopping cart. In this way, the entire page doesn't need to submit, only a hidden IFRAME, and I can make sure that if the user decides to hit the back button at any time, or even browse away from the page and come back, their...
5
2933
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 author source ). Now I've added the option to make text in BOLD etc (code found on this forum), BUT it doesn't work.... This is the code (within a php file): <div align="center"> <table style="width:600px;border:solid 1px...
4
1958
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 =\"http://www.sitename.com/app/score.php?quiz_id=".$_SESSION."&uid=0\" width=\"480\" height=\"925\" scrolling=\"no\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>".$show_commander, ENT_QUOTES); But when adding PHP code into it its all...
0
9704
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.