SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,045
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    pre load html code into WYSIWYG editor

    Hi Guys,

    I am trying to load the following html code into a WYSIWYG editor. Basically all I need to do is supply the html code to the 'rte1.html' var and it should load in the editor. However, I am receiving the following error:

    Code:
    Unterminated string constant
    Here is my code:

    HTML Code:
    <script language="javascript" type="text/javascript">
    			<!--
    			rte1.html = 'Smartscript - Company information</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="images/style.css" rel="stylesheet" type="text/css">
    </head>
    <body bgcolor="#EDEDED" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <table width="75%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td class="headerwrap">
    	<table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td class="headerL">&nbsp;</td>
              <td class="headerlogo"><a href="index.php"><img src="images/spacer.gif" alt="Smartscript" width="251" height="100" border="0"></a></td>
              <td align="right" valign="top" class="afterlogo">&nbsp;</td>
            <td class="headerR">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td class="navwrap"><table id="navstyle" width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><div align="center"><a href="index.php" title="Smartscript home">Home</a></div></td>
            <td valign="top" class="divider">&nbsp;</td>
            <td><div align="center"><a href="products.php" title="Smartscript products">Products</a></div></td>
            <td valign="top" class="divider">&nbsp;</td>
            <td><div align="center"><a href="company.html" title="About Smartscript">Company</a></div></td>
            <td valign="top" class="divider">&nbsp;</td>
            <td><div align="center"><a href="members" title="Members area">Members</a></div></td>
    		<td valign="top" class="divider">&nbsp;</td>
            <td><div align="center"><a href="partners.php" title="Smartscript partners">Partners</a></div></td>
            <td valign="top" class="divider">&nbsp;</td>
            <td><div align="center"><a href="contact-us.php" title="Contact Smartscript">Contact us</a></div></td>
            <td valign="top" class="divider">&nbsp;</td>
            <td><div align="center"><a href="forums" title="Smartscript forums">Forums</a></div></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td align="right" valign="top" class="cwrap"><table width="100%" border="0" cellspacing="10" cellpadding="0">
            <tr> 
              <td valign="top" class="standard"><div class="centertitle">&nbsp;About Smartscript</div>
                <table width="100%" border="0" cellspacing="0" cellpadding="5">
                  <tr> 
                    <td colspan="2" class="standard"><p>Smartscript is an innovative 
                        software development company which specializes in PHP &amp; 
                        MySQL applications. Smartscript maintain a high reputation 
                        for providing powerful, reliable and innovative products.</p>
                      </td>
                  </tr>
                </table></td>
            </tr>
          </table>
          <p class="standard">&copy; 2003 - 2006 Smartscript. All rights reserved&nbsp;</p>
        </td>
      </tr>
      <tr>
        <td class="footwrap"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="footwraptable">
          <tr>
            <td class="footL">&nbsp;</td>
            <td>&nbsp;</td>
            <td class="footR">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
    </table>
    <p>&nbsp;</p>
    </body>
    </html>';
    			//-->
    			</script>
    Thanks in advance

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try to put + at the end of every line (except last one)of string content and check if there's any apostrophe in string because it shouldn't be.

  3. #3
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,045
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bosko View Post
    Try to put + at the end of every line (except last one)of string content and check if there's any apostrophe in string because it shouldn't be.
    As my html code is pulled from a database it's going to make it hard to add a + at the end of each line. Would there be an easier way to do it? Also, I checked for apostophe's and there were none.

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Location
    Sydney, Australia
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    This error occurs when there are characters in the string which terminate the javascript variable prematurely, in your case it looks like newlines..what you need is a function that strips these characters BEFORE you feed it to the javascript variable. So if you can tell me what server side language you are using (php,.net,asp etc). I will be able to knock something up for you that will fix this problem. Unfortunately theres no javascript way of doing this, because at the very point you feed this data to javascript is when it breaks.
    Kind Regards,
    Steve
    http://www.rtepad.com

  5. #5
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,045
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Steve@rtePad View Post
    Hi,

    This error occurs when there are characters in the string which terminate the javascript variable prematurely, in your case it looks like newlines..what you need is a function that strips these characters BEFORE you feed it to the javascript variable. So if you can tell me what server side language you are using (php,.net,asp etc). I will be able to knock something up for you that will fix this problem. Unfortunately theres no javascript way of doing this, because at the very point you feed this data to javascript is when it breaks.
    Hi Steve,

    I am using PHP - thanks for your help on this, it is greatly appreciated.

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Location
    Sydney, Australia
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?php
    function rtePreload($html)
    {
    $html = str_replace(chr(147), chr(34), $html);
    $html = str_replace(chr(148), chr(34), $html);
    $html = str_replace(chr(145), chr(39), $html);
    $html = str_replace(chr(146), chr(39), $html);
    $html = str_replace("'", "'", $html);
    $html = str_replace(chr(10), " ", $html);
    $html = str_replace(chr(13), " ", $html);
    return $html;
    }

    $content = rtePreload($_POST["content"]);
    ?>
    <script>
    initRTE('<?= $content ?>');
    </script>

    Feel free to change the code accordingly to suit your needs and wysiwyg editor you are using.
    Kind Regards,
    Steve
    http://www.rtepad.com

  7. #7
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,045
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! It works great!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •