0

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,

1
  • 1
    What's wrong with onClick="javascript:popup('actionpage.php?foo=bar&blah=baz')? Commented Feb 16, 2012 at 7:20

5 Answers 5

1

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

Sign up to request clarification or add additional context in comments.

Comments

0
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');");
}

Comments

0

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);

Comments

0

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'];
?>

Comments

0

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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.