usertfwr
usertfwr

Reputation: 309

php & javascript open window function

I try to use window.open but so far it doesn't work

<script type="text" language="javascript">    
function win1(j){
    window.open("ctry.php?j=" + j,"Window1","menubar=no,width=460,height=360,toolbar=no");
}
</script>

<?php
for($j = 1; $j <= 2; $j++){  
?>
<a href="javascript:win1('<?php echo $j;?>')" 
  onMouseOver="self.status='Open A Window'; return true;"><b>Open Window</b></a>
<?php
}
?>

When I click on the link nothing happened and on the console i get this error:

Uncaught ReferenceError: win1 is not defined 

Do you know what can i do? Thanks

Upvotes: 0

Views: 2088

Answers (4)

amandanovaes
amandanovaes

Reputation: 704

Are you putting this code inside body tag or inside head? Cause you cannot put html in head

Upvotes: 0

Manu
Manu

Reputation: 150

use this

<script type="text/javascript" language="javascript">
function win1(j){
    window.open("ctry.php?j=" + j,"Window1","menubar=no,width=460,height=360,toolbar=no");
}
</script>

<?php
for($j = 1; $j <= 2; $j++){  
?>
<a href="javascript:void(0)"  onMouseOver="self.status='Open A Window'; return true;" onClick="win1('<?php echo $j;?>')"><b>Open Window</b></a>
<?php
}
?>

Upvotes: 2

web-nomad
web-nomad

Reputation: 6003

Replace <script type="text" language="javascript"> with <script type="text/javascript" language="javascript">

Upvotes: 1

San
San

Reputation: 624

Your JS action is to be on onclick action, not on href, try this elow code

<a href="#" onclick="win1('<?php echo $j;?>')"
  onMouseOver="self.status='Open A Window'; return true;"><b>Open Window</b></a>

Upvotes: -1

Related Questions