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
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;

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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\')'"/>'"

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 -->";
            
}

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.