0

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

1

4 Answers 4

2

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
}
?>
Sign up to request clarification or add additional context in comments.

1 Comment

<a href="javascript:win1('<?php echo $j;?>')" onMouseOver="self.status='Open A Window'; return true;"><b>Open Window</b></a> This will also work.
1

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

Comments

0

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

1 Comment

It is known from the question that the link is displayed in the output.
-1

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.