I need to open a popup window from a PHP site and pass in some parameters to use in the pop up window.

I have the params in an input box and need to get the val of the box into a param and pass it to the new popup window. All pages are local and in the same folder. The id of the input box is 'ddutykey'. The name of the new window would be showduty.php if possible.

Any help would be appreciated.
Bill

Recommended Answers

All 3 Replies

Well if the pop-up window is a new paged that is displaying the data, then you want to pass the data via URL..

function passData() {
    var input1 = document.getElementById("input.name").value;
    window.open("showduty.php?param1="+input1);
}

Let me know if this is what you are looking for?

Thanks, this works fine in FF.

My code: window.open("showduty.php?dutykey=" + encodeURIComponent(cstr), "mywindow, width=350,height=250" );

In IE I get an "Invalid argument". Any ideas why this might be happening?

Well if the pop-up window is a new paged that is displaying the data, then you want to pass the data via URL..

function passData() {
    var input1 = document.getElementById("input.name").value;
    window.open("showduty.php?param1="+input1);
}

Let me know if this is what you are looking for?

Well the invalid argument is the name that your trying to give it. Now you can adjust this without using top and left, but i do this because when the user clicks on the link the popup window opens in the middle of the screen. If you dont want top and left, just delete them out of the string.

<script type="text/javascript">
var popUpWin = 0;
function popUpWindow(URLStr, width, height) { 
    if(popUpWin) {
        if(!popUpWin.closed) popUpWin.close();
    }
    // now this is where you can delete this "top and left".
    // If you do, delete, "top, left, screenX, screenY".
    var left = document.body.clientWidth/2;
    var top = document.body.clientHeight/2;
    var input1 = document.getElementById("input1").value;
    popUpWin = open(URLStr+'?param1='+input1, 'popUpWin', 'toobar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top+'');
}
</script>

<a onclick="popUpWindow('showduty.php',200,200)">click to open</a>

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.