user2322921
user2322921

Reputation: 5

javascript new popup page in php

I'm new in web programming and I have some problem. I want to open a new popup php page from a link clicked but is not work..

from this link

echo '<td><a href="#" onClick = "open("../common/sqlDetail_Inform_Reservation.php?id='.$row['Reservation_ID'].'");">OPEN</a></td>';

Script function

function open(url) {
      var popup = window.open(url, "_blank", "width=200, height=200") ;
      popup.location = url;
    }

Best regard : D

Upvotes: 0

Views: 206

Answers (3)

cocco
cocco

Reputation: 16716

This is a elegant solution to avoid to many click handlers,it uses the new attribute data-SOMETHING to store your id.if you want more compatibility you can also use the rel attribute or title or whatever to store the id. less code,faster javascript,easy to edit later.

<table>
<?php
while($row blabla ){
 echo "<tr>
  <td>".$row['bla1']."</td>
  <td data-id=\"".$row['Reservation_ID']."\">open</td>
 </tr>";
}
?>
</table>
<script>
function open(e){
 if(e.target.dataset['id']){
  window.open('blabla/Reservation.php?id='+e.target.dataset['id']);
 }
}
document.getElementsByTagName('table')[0].addEventListener('click',open,false)
</script>

if you don't understand something just ask

example in javascript...

http://jsfiddle.net/V5Kn5/

Upvotes: 0

Tib
Tib

Reputation: 2631

You have conflict with quotes, try with that:

echo '<td><a href="#" onClick = "open(\'../common/sqlDetail_Inform_Reservation.php?id='.$row['Reservation_ID'].'\');">OPEN</a></td>';

Upvotes: 1

John Conde
John Conde

Reputation: 219914

You have a quotes issue. You need to escape your double quotes that inside a double quoted string:

echo '<td><a href="#" onClick = "open(\"../common/sqlDetail_Inform_Reservation.php?id='.$row['Reservation_ID'].'\");">OPEN</a></td>';

Upvotes: 2

Related Questions