Search code examples
javascriptphphtmlpopupwindow.open

window.open doesn't do anything


I'm trying to show some info in a pop-up window usig a window.open.. but when I click nothing happens.

This is the function that opens a new window.

function goNewWin(sell_code){

// Set height and width
var NewWinHeight=1000;
var NewWinWidth=1000;

// Place the window
var NewWinPutX=10;
var NewWinPutY=10;

//Get what is below onto one line

TheNewWin =window.open("renovations_history.php?sell_code=" + sell_code,
'Renovaciones','fullscreen=yes,toolbar=no,location=no,status=no,menubar=no,scrollbars=no');

//Get what is above onto one line

TheNewWin.resizeTo(NewWinHeight,NewWinWidth);
TheNewWin.moveTo(NewWinPutX,NewWinPutY);

}
</script>

Here's the HTML, with some PHP.

<form>
  <input type="button" value="Renovaciones" onClick="goNewWin(<?php echo $row['sell_code']; ?>)">
</form>

Nor it works with:

<a href="javascript:goNewWin(<?php echo $row['sell_code']; ?>)">Renovaciones</a>

It's 2:22 am and I can think straight, please help.


Solution

  • You need to add single quotes to the JavaScript function call:

    <?php
    $sell_code = $row['sell_code'];
    ?>
    <input type="button" value="Renovaciones" onClick="goNewWin('<?php echo $sell_code]; ?>')">
    

    Without it, Javascript will consider your $row['sell_code'] as a javascript keyword.

    You need to pass it as a string (function parameter).

    Reference