Note that there are some explanatory texts on larger screens.

plurals
  1. POexpanding a quoted string within another string
    primarykey
    data
    text
    <p>I have two variables containing some html code, and another variable containing code for a html form. I am trying to expand a string within the second to pass it as a parameter to a function, however this causes some errors.</p> <p>My make popup function is very simple:</p> <pre><code>function popup(htmlcode){ child1 = window.open ("about:blank"); child1.document.write(htmlcode); child1.document.close(); } </code></pre> <p>The code that uses the above function</p> <pre><code>&lt;?php $blah = "&lt;h1&gt;Well&lt;/h1&gt;"; $test = "&lt;h2&gt;Done&lt;/h2&gt;"; echo '&lt;script type="text/javascript" src="fetchlayers.js"&gt;&lt;/script&gt;'; $formcode = "&lt;form action=\"process.php\" method=\"post\" enctype=\"multipart/form-data \"&gt; &lt;label for=\"file\"&gt;Filename:&lt;/label&gt; &lt;input type=\"file\" name=\"file\" id=\"file\"/&gt; &lt;br /&gt; &lt;input type=\"submit\" name=\"submit\" value=\"Submit\" onclick=\"setTimeout(function() { sendInfo(\"".$blah."\", \"".$test."\"); } ),1250);\" /&gt; &lt;/form&gt;"; echo "&lt;h1&gt;hello&lt;/h1&gt; &lt;div id='form'&gt; &lt;a href='#' onclick=\"popup('" . htmlentities($formcode) . "'); return false;\"&gt; click here&lt;/a&gt; &lt;/div&gt;"; </code></pre> <p>This produces decent enough html code, however firebug gives me an error that I have an unterminated string lateral. I cannot find where this is. I understand the way I have done this is not ideal, but I am learning and do not know a better way at present. I appreciate any input</p> <p>edit: OK, so the problem was that I had unterminated string literals, which were \n characters. I made the string into one line and it called the function correctly.</p> <p>Is it not possible to break one echo statement into multiple lines?</p> <p>Now the problem is with the html generated in the popupwindow. Some of the code is actually printed to the screen, why is this?</p> <pre><code>&lt;form action="process.php" method="post" enctype="multipart/form-data "&gt;&lt;label for="file"&gt;Filename:&lt;/label&gt;&lt;input name="file" id="file" type="file"&gt; &lt;br&gt;&lt;input name="submit" value="Submit" onclick="setTimeout(function() { sendInfo(" type="submit"&gt;&lt;h1&gt;Well&lt;/h1&gt;", "&lt;h2&gt;Done&lt;/h2&gt;"); },1250);" /&gt;&lt;/form&gt; </code></pre> <p>See the image <a href="http://i44.tinypic.com/14t22k9.jpg" rel="nofollow noreferrer">here</a>:</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload