cturner Posted July 17, 2007 Share Posted July 17, 2007 I am trying to build a rich text editor for a client of mine. However I can only get the text from the database to be displayed every where else but the iframe. Can someone please help me get the text into the iframe? Thanks in advance. // the getting text from the database code <?php require "config.php"; $query = mysql_query ("SELECT * FROM tbl_articles") or die ("Could not query because: ".mysql_error()); $row = mysql_fetch_assoc($query); $id = $row['id']; $article = $row['article'];' ?> // the iframe <iframe id="textEditor" name="textEditor" style="width:500px; height:200px;"></iframe> // the code to display the text in the iframe <script language="javascript"> textEditor.document.designMode="on"; textEditor.document.open(); textEditor.document.write('<head><style type="text/css">body{ font-family:verdana; font-size:10px; }</style></head>'); textEditor.document.write( </script> <?php echo $article; ?> <script language="javascript"> ); textEditor.document.close(); </script> // close the database <?php mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted July 17, 2007 Share Posted July 17, 2007 What you will need to do is pass the php variables to javascript from javascript you can pass it to the iframe Quote Link to comment Share on other sites More sharing options...
cturner Posted July 17, 2007 Author Share Posted July 17, 2007 What you will need to do is pass the php variables to javascript from javascript you can pass it to the iframe How? Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted July 17, 2007 Share Posted July 17, 2007 this is how you pass a php variable to javascript. <script> var myJSvar="<php? echo($phpVar);?>"; </script> now you have a javascript variable that you can pass to the iframe there are loads of examples how to pass a js var from one frame to another try and google it up Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted July 17, 2007 Share Posted July 17, 2007 I've not tried this when using an iframe for RTE purposes, but what about setting up a script that takes an article ID through $_GET and displays the article. Then you could just set the src attribute of the iframe to that script. Quote Link to comment Share on other sites More sharing options...
cturner Posted July 17, 2007 Author Share Posted July 17, 2007 I had tried what you said Dj Kat but that didn't work. Anyway I tried <iframe id="textEditor" name="textEditor" src="<?php echo 'http://www.blueguminteractive.biz/myrte/phppage.php'; ?>" style="width:500px; height:200px;"></iframe> that worked for me. The phppage.php has the code for getting the article. Now there is another problem the iframe is not editable. Is there a way to make the iframe editable? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted July 17, 2007 Share Posted July 17, 2007 Assign an onload handler to the iframe that sets the designMode property to "on". Take note there are differences between IE and Mozilla as to which object is the owner of designMode. If you follow the link in my signature I have a couple of blog posts about creating RTEs with Javascript. I can't guarantee that it'll help you but it might. Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted July 17, 2007 Share Posted July 17, 2007 I remembered answering a similar question check this link out it might help http://www.phpfreaks.com/forums/index.php/topic,147397.0.html <iframe id="textEditor" name="textEditor" src="<?php echo 'http://www.blueguminteractive.biz/myrte/phppage.php'; ?>" I think that won't work btw since your iframe will contain the text editor Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.