-2

I have 2 loops within 1 form where a link gets created within each loop. The first link on the first loop opens a pop up but all other links will open a new page. Not sure why all links don't open in a pop up

<script>
$(document).ready(function() {
$('#Popup').click(function() {
    var newwindow = window.open($(this).prop('href'), '', 
   'height=800,width=800');
    if (window.focus) {
        newwindow.focus();
    }
    return false;
});
});
</script>

<form method='post' target = '_blank'>

foreach(do something){ 
echo "<a href='newpage1.php?cmd=get stuff" id='Popup''>View</a>";
}

foreach(do something){ 
echo "<a href='newpage2.php?cmd=get stuff" id='Popup''>View</a>";
}
</form>
Gino
  • 189
  • 2
  • 10

1 Answers1

0

Each link should have the same class, not have the same id (ids must be unique).

<a href="newpage1.php?cmd=get stuff" class="Popup">View</a>

Then, in your javascript, use the class selector.

$('.Popup').click(function() {
  // Will be applied to all in class
});
Nick
  • 16,066
  • 3
  • 16
  • 32