tags:

views:

161

answers:

3

I have this short code linked that is sent from a php file:

{
$sql="SELECT * FROM Auctions WHERE ARTICLE_NO ='$pk'";
$sql2="SELECT ARTICLE_DESC FROM Auctions WHERE ARTICLE_NO ='$pk'";
$htmlset = mysql_query($sql2);
$row2 = mysql_fetch_array($htmlset);
echo '<script> 
function makewindows(){
child1 = window.open ("about:blank");
child1.document.write('.$row2["ARTICLE_DESC"].');
child1.document.close(); 
}
</script>';

And I have a link that should call makewindows() onclick, however I get a script error that does not give any details, that prevents the script from even being loaded. I am unsure as to why this could be.

edit:

this is the html code that is generated, for some reasins the entire contents of ARTICLE_DESC is not assigned or written.

<script> 
function makewindows(){
child1 = window.open ("about:blank");
child1.document.write("<!-- +++++++++++++++++++++++++ Bitte ändern Sie im eigenen Interesse nichts an diesem Code! ++++++++++++++++++++++++ -->
<!-- +++++++++++++++++++++++++ Das kann massive Fehldarstellungen ihrer Auktion zur Folge haben! +++++++++++++++++++ -->
<!-- +++++++++++++++++++++++++ ++++++++++++++++++++++++++ Ihr Supreme Team +++++++++++++++++++++++++++++++++++++++++ -->
");
child1.document.close(); 
}
</script><br />
<b>Notice</b>:  Undefined index:  CATEGORY in <b>C:\Programme\EasyPHP 2.0b1\www\get_auction.php</b> on line <b>39</b><br />
<div id='leftlayer'>
    <strong>Article Number</strong> 220288560247
    <p><strong>Article Name</strong></p> Ed Hardy Herren Shirt Rock & Roll Weiss XXL Neu & OVP
    <p><strong>Subtitle</strong></p> 
    <p><strong>Username</strong></p> fashionticker1
    <p><strong>Total Selling</strong></p> 1
    <p><strong>Total Sold</strong></p> 0
    <p><strong>Category</strong></p> 
    <p><strong>Highest Bidder</strong></p> 0
  </div>
<div class='leftlayer2'>
  <strong>Current Bid</strong> 0.00
  <p><strong>Start Price</strong></p> 49.00
  <p><strong>Buyitnow Price</strong></p> 59.00
  <p><strong>Bid Count</strong></p> 0
  <p><strong>Start Date</strong></p> 1.10.2008 16:22:09
  <p><strong>End Date</strong></p> 6.10.2008 16:22:09
  <p><strong>Original End</strong></p> 6.10.2008 16:22:09
  <p><strong>Auction Type</strong></p> 1
</div>
<div class='leftlayer2'>
    <strong>Private Auction</strong></p> 0
  <p><strong>Paypal Accepted</strong></p> 0
  <p><strong>Auction Watched</strong></p> 0
  <p><strong>Finished</strong></p> 1
  <p><strong>Country</strong></p> 
<br>
<br>
<style ty
  <p><strong>Location</strong></p> float: right;

  <p><strong>Conditions</strong></p> margin: 0px;

</div>
<div class='leftlayer2'>
  <strong>Auction Revised</strong></p> 0
  <p><strong>Cancelled</strong></p> 0
  <p><strong>Shipping to</strong></p> padding:5px; 

  <p><strong>Fee Insertion</strong></p> 0.00
  <p><strong>Fee Final</strong></p> 0.00
  <p><strong>Fee Listing</strong></p> 0.00
  <p><a href='#' onclick='makewindows(); return false;'>Click for full description </a></p>
</div><div id='rightlayer'>Picture Picture
<img src=http://storage.supremeauction.com/flash/ebay2/10/49/76/10497654/13895964e.jpg&gt;
</div>

For whatever reason the img at the bottom of the html will not dispaly within the html

+7  A: 

Make sure you have quotes in the contents of your document.write

echo '<script> 
function makewindows(){
child1 = window.open ("about:blank");
child1.document.write("'.$row2["ARTICLE_DESC"].'");
child1.document.close(); 
}
</script>';
Nick Berardi
this loads the JavaScript, but I get an error when clicking and attempting to call the function
Joshxtothe4
That is because it is probably in the wrong place on your page. Please post the HTML of how and where you are calling the function.
Nick Berardi
+1  A: 

It could be that javascript doesn't like the multi-line string. I copied your HTML and once I had removed the line breaks no longer got an error.

It is probably best to json_encode() the string as Roborg suggested in your earlier question today. Alternatively you could try to do something like strip out the line breaks before putting it into the javascript string. Note that the json_encode() method will also sort out your quotes - currently if you HTML contains a double-quote character your javascript string will be broken.

Tom Haigh
You need a newline/escaping character ('\') at the end of each line in multiline javascript strings
Chris MacDonald
yeah, but adding them would be a bit messy when the string is coming from the database - it would surely be cleaner to strip them out completely?
Tom Haigh
Does it matter to mix JSON and AJAX?
Joshxtothe4
I'm not really sure what you mean - they are used extensively together. Using json_encode() will convert a php data structure into something javascript will easily understand.
Tom Haigh
A: 

the script that you are outputing can be better. use this:

...
$documentContent = addslashes( $row2['ARTICLE_DESC'] );
$output = <<< endOfOutput
<script type="text/javascript">
    function makewindows(){
        var child1 = window.open ('','child1');
        child1.document.open();
        child1.document.write('{$documentContent}');
        child1.document.close();
    }
</script>
endOfOutput;
echo $output;

don't forget the quotes inside the document.write(). these quotes are part of the output string, not quotes for PHP to enclose the string.

farzad
I copied and pasted your example, but I just get an unexpected T_START_HEREDOC error on the second line after defining $output.
Joshxtothe4
I corrected it. I had forgotten to place the equal sign in line where the HEREDOC syntax begins (the line with <<< ). anyway I remembered I had the same problem. the problem is solved by using the addslashes() method. it escapes all quote characters from the string you are outputing.
farzad