debuitls Posted September 17, 2009 Share Posted September 17, 2009 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? Quote Link to comment Share on other sites More sharing options...
khr2003 Posted September 17, 2009 Share Posted September 17, 2009 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; Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 17, 2009 Share Posted September 17, 2009 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. Quote Link to comment Share on other sites More sharing options...
debuitls Posted September 17, 2009 Author Share Posted September 17, 2009 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 € </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 Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 17, 2009 Share Posted September 17, 2009 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\')'"/>'" Quote Link to comment Share on other sites More sharing options...
debuitls Posted September 17, 2009 Author Share Posted September 17, 2009 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 € </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 Quote Link to comment Share on other sites More sharing options...
khr2003 Posted September 17, 2009 Share Posted September 17, 2009 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 -->"; } Quote Link to comment Share on other sites More sharing options...
khr2003 Posted September 17, 2009 Share Posted September 17, 2009 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; } Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 17, 2009 Share Posted September 17, 2009 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. Quote Link to comment Share on other sites More sharing options...
debuitls Posted September 17, 2009 Author Share Posted September 17, 2009 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? Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 17, 2009 Share Posted September 17, 2009 Hi debuitls, Change your Javascript onClick function to read: onClick="window.open(\'viewhotel.php?id='.$row['id'].'\', \'mywindow\', \'width=400, height=200\') Hope this helps. Quote Link to comment Share on other sites More sharing options...
debuitls Posted September 17, 2009 Author Share Posted September 17, 2009 Thanks for all your help Bricktop. This is working perfectly now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.