Jump to content

echoing js window.open function


debuitls

Recommended Posts

Hi all,

 

Im trying to figure out how to echo the js on click window.open function.

 

I'm running into some syntax problems though im afraid.

 

I've tried this

 

"<input type=\"image\" src=\"ViewHotel.PNG\" name=\"image\" width=\"90\" height=\"24\" onClick=\"window.open('viewhotel.php?id='.$row['id'].', 'mywindow', 'width=400, height=200')'\"/>"

 

 

This line of code is concatonated on either side with other code and echoed.

 

Can anyone point out where im going wrong?

 

Link to comment
https://forums.phpfreaks.com/topic/174549-echoing-js-windowopen-function/
Share on other sites

Try to use this approach in order to get rid of (\" or \')

 

echo <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon. no extra whitespace!
END;

Hi debuitls,

 

It's the mixture of speechmarks " and apostrophes ' that are causing the problem, give this a go:

 

echo '<input type="image" src="ViewHotel.PNG" name="image" width="90" height="24" onClick="window.open(\'viewhotel.php?id='.$row['id'].', \'mywindow\', \'width=400, height=200\')'"/>';

 

Hope this helps.

Thanks for getting back to me Bricktop,

 

That seemed to resolve the problem in that line but it looks like the line is causing a problem when I put it in the full statement.

 

while($row = mysql_fetch_array($result))
{
echo '<div class="rbroundbox">
<div class="rbtop"><div></div></div>
	<div class="rbcontent">'.'<div class="mydiv">'."  ".$row['hotelname'].", ".$row['address1'].", ".$row['address2'].", ". $row['county'].'</div>'."<p>     </p>".'<div class="urdiv">'."<br/>"."       "."<img src=http://www.xyz.com/Website/images/".$row['logo'] ." alt='logo' rel='lightbox[mando]' border='1' height='100' width='100'>"." ".'</div>'.'<div class="hisdiv">'."<br/>"." <font size = '6'> <strong><b>Hotel Bids &#8364 </b></strong></font>"."<font size = '6'>"."<strong>".$row['hotelprice']."</strong>"."</font size>"."<br />"." Includes:  ".$row['addons']."<br />"."Reference Number: " . $row['bookingref'].
	'<br/>'.'<br />'."                                      ".
	'<input type="image" src="BookThisHotel.PNG" name="image" width="121" height="24" onclick="window.location=\'bookview.php?em='. $row['email'].'&id='. $row['bookingref'].'&te='.$row['telephone'].'&nh='.$row['hotelname'].'\'">'." ".
'<input type="image" src="ViewHotel.PNG" name="image" width="90" height="24" onClick="window.open(\'viewhotel.php?id='.$row['id'].', \'mywindow\', \'width=400, height=200\')'"/>'
	.'</div>'.'</div><!-- /rbcontent -->    
<div class="rbbot"><div></div></div>
</div><!-- /rbroundbox -->';

}

     ?>	

 

I know its a lot of code but just have a look at the line towards the end after I insert the new line of code. I think there is something wrong here. Can anyone spot what it is? It works fine without the new line of code. 

 

Thanks

 

Hi Debuitls,

 

Try adding a speechmark " at the end of the line of code you've just added.  Copy and paste the below and give that a try.

 

'<input type="image" src="ViewHotel.PNG" name="image" width="90" height="24" onClick="window.open(\'viewhotel.php?id='.$row['id'].', \'mywindow\', \'width=400, height=200\')'"/>'"

ok so notepad has stopped highlighting any errors in the code but im still just getting a white page when I load.

 

while($row = mysql_fetch_array($result))
{
echo '<div class="rbroundbox">
<div class="rbtop"><div></div></div>
	<div class="rbcontent">'.'<div class="mydiv">'."  ".$row['hotelname'].", ".$row['address1'].", ".$row['address2'].", ". $row['county'].'</div>'."<p>     </p>".'<div class="urdiv">'."<br/>"."       "."<img src=http://www..com/Website/images/".$row['logo'] ." alt='logo' rel='lightbox[mando]' border='1' height='100' width='100'>"." ".'</div>'.'<div class="hisdiv">'."<br/>"." <font size = '6'> <strong><b>Hotel Bids &#8364 </b></strong></font>"."<font size = '6'>"."<strong>".$row['hotelprice']."</strong>"."</font size>"."<br />"." Includes:  ".$row['addons']."<br />"."Reference Number: " . $row['bookingref'].
	'<br/>'.'<br />'."                                      ".
	'<input type="image" src="BookThisHotel.PNG" name="image" width="121" height="24" onclick="window.location=\'bookview.php?em='. $row['email'].'&id='. $row['bookingref'].'&te='.$row['telephone'].'&nh='.$row['hotelname'].'\'">'." ".
	'<input type="image" src="ViewHotel.PNG" name="image" width="90" height="24" onClick="window.open(\'viewhotel.php?id='.$row['id'].', \'mywindow\', \'width=400, height=200\')'"/>'"
	.'</div>'.'</div><!-- /rbcontent -->    
<div class="rbbot"><div></div></div>
</div><!-- /rbroundbox -->';

}

    ?>	

 

Heres the updated code. Again it seems fine when I remove that line.

 

Does anyone have any more suggestions. Thank you

I do not understand why you use ' so often. check this code and see if it working:

 


while($row = mysql_fetch_array($result))
{
   echo "<div class="rbroundbox">
   <div class="rbtop"><div></div></div>
      <div class="rbcontent"><div class="mydiv">  $row['hotelname'] $row['address1'] $row['address2'],  $row['county'].'</div>'<p>     </p>'<div class='urdiv'>'<br/>       <img src=http://www..com/Website/images/$row['logo']  alt='logo' rel='lightbox[mando]' border='1' height='100' width='100'> </div><div class='hisdiv'><br/><font size = '6'> <strong><b>Hotel Bids € </b></strong></font><font size = '6'><strong>$row['hotelprice']</strong></font size><br /> Includes:  $row['addons']<br />Reference Number:  . $row['bookingref'].
      <br/><br />                                      
      <input type='image' src='BookThisHotel.PNG' name='image' width='121' height='24' onclick=\"window.location='bookview.php?em=$row['email']&id=$row['bookingref']&te=$row['telephone']&nh=$row['hotelname']\"> 
      <input type='image' src='ViewHotel.PNG' name='image' width='90' height='24' onClick=\"window.open('viewhotel.php?id=$row['id'], 'mywindow', 'width=400, height=200')\">
      </div></div><!-- /rbcontent -->   
   <div class=\"rbbot\"><div></div></div>
</div><!-- /rbroundbox -->";
            
}

or this code:

 

while($row = mysql_fetch_array($result))
{
  echo <<<END
  
  <div class="rbroundbox">
   <div class="rbtop"><div></div></div>
      <div class="rbcontent"><div class="mydiv">  $row['hotelname'] $row['address1'] $row['address2'],  $row['county'].'</div>'<p>     </p>'<div class='urdiv'>'<br/>       <img src=http://www..com/Website/images/$row['logo']  alt='logo' rel='lightbox[mando]' border='1' height='100' width='100'> </div><div class='hisdiv'><br/><font size = '6'> <strong><b>Hotel Bids € </b></strong></font><font size = '6'><strong>$row['hotelprice']</strong></font size><br /> Includes:  $row['addons']<br />Reference Number:  . $row['bookingref'].
      <br/><br />                                      
      <input type='image' src='BookThisHotel.PNG' name='image' width='121' height='24' onclick="window.location='bookview.php?em=$row['email']&id=$row['bookingref']&te=$row['telephone']&nh=$row['hotelname']"> 
      <input type='image' src='ViewHotel.PNG' name='image' width='90' height='24' onClick="window.open('viewhotel.php?id=$row['id'], 'mywindow', 'width=400, height=200')">
      </div></div><!-- /rbcontent -->   
   <div class="rbbot"><div></div></div>
</div><!-- /rbroundbox -->";
END;
}

Hi debuitls,

 

I've been through all of your code and tidied it up, it should now work;

 

while($row = mysql_fetch_array($result))
{
echo '<div class="rbroundbox">
<div class="rbtop"><div></div></div>
<div class="rbcontent"><div class="mydiv"> '.$row['hotelname'].', '.$row['address1'].', '.$row['address2'].', '. $row['county'].'</div>
<p>  </p>
<div class="urdiv"><br/>       <img src=http://www..com/Website/images/'.$row['logo'] .' alt="logo" rel="lightbox[mando]" border="1" height="100" width="100"> </div>
<div class="hisdiv"><br/><font size = "6"><strong><b>Hotel Bids € </b></strong></font><font size = "6"><strong>'.$row['hotelprice'].'</strong></font size><br />Includes:  '.$row['addons'].'<br />Reference Number: ' . $row['bookingref'].'<br/><br />                                     
	<input type="image" src="BookThisHotel.PNG" name="image" width="121" height="24" onclick="window.location=\'bookview.php?em='.$row['email'].'&id='.$row['bookingref'].'&te='.$row['telephone'].'&nh='.$row['hotelname'].'\'"> 
	<input type="image" src="ViewHotel.PNG" name="image" width="90" height="24" onClick="window.open(\'viewhotel.php?id='.$row['id'].', \'mywindow\', \'width=400, height=200\')"/></div></div><!-- /rbcontent -->  
<div class="rbbot"><div></div></div>
</div><!-- /rbroundbox -->';

}

    ?>	

 

Hope this helps.

Thank you for your time and help Bricktop.

 

The page is loading now fine.

 

However, when you click on the image it fails to open a the new window with the page in it.

 

Can anyone suggest why this might be the case?

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.