简体   繁体   中英

Passing values for PHP page from JavaScript Popup

I have a Popup button written in JavaScript. When user clicks that button, it opens a PHP popup. While clicking, i want to pass values through GET or POST method to that PHP page, Here is my code for Popup button:

<form input type="BUTTON" value="popup button" onClick="javascript:popup('actionpage.php')">
</form>

<SCRIPT LANGUAGE="JavaScript">    
function popup(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=880,height=300');");
}

</script>

Here i want to pass values to actionpage.php when user clicks "popup button". Thanks and Regards,

onClick="javascript:popup('actionpage.php?foo=bar')"

You can pass parameters on your querystring and process them server-side in your PHP page.

Also note that the use of eval() is unneeded and generally frowned upon and your FORM/INPUT tags are malformed. I believe I've corrected it in the following example.

<form>
    <input type="button" value="popup button" onclick="popup('actionpage.php')" />
</form>

<script>    

function popup(URL) {

    var day = new Date();
    var id = day.getTime();

    window.open(
        URL + "?id=" + id, 
        'toolbar=0, 
         scrollbars=0,
         location=0,
         statusbar=0,
         menubar=0,
         resizable=0,
         width=880,
         height=300'
    );
}

</script>

you can send data using this code:

var http = new XMLHttpRequest();
http.open("POST", 'path/to/php', true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.send(params);
function popup(URL) {
day = new Date();
**URL=URL+"?foo=bar&foo2=bar2";**
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=880,height=300');");
}

Hope this will help you.

<form>
<input type="BUTTON" value="popup button" onClick="javascript:popup('array.php')">
</form>

<SCRIPT LANGUAGE="JavaScript">    
function popup(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL + '?id=' + id , '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=880,height=300');");
}

</script>

In PHP page just use $_GET['id'] to obtain the ID.

<?php
$id = $_GET['id'];
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM