Riquelmy Melara
Riquelmy Melara

Reputation: 941

How to send JS variable to php iFrame

I have this variable on my form

<script>
     var type = 2;
</script>

and on the same page I am calling this iFrame

<iframe src='http://www.genpowerusa.com/crm/formal_quote_new2.php' frameborder='0'></iframe>

What I am unsure is, how could I send the variable to the php form and use the variable on the quote form, the variable is static, I have two pages that call the same iFrame.

Is such thing possible?

Upvotes: 0

Views: 505

Answers (2)

phpcoderx
phpcoderx

Reputation: 570

Assign an id to your iframe:

<iframe id='foo' src='http://www.genpowerusa.com/crm/formal_quote_new2.php' frameborder='0'></iframe>

Add a js line:

document.getElementByid("foo").src='http://www.genpowerusa.com/crm/formal_quote_new2.php?type='+type;

What this does is,pass your variable as a PHP url parameter.You can access it by using the following code in php:

$type=$_GET['type'];

Upvotes: 2

Bram
Bram

Reputation: 4532

Sending information via javascript to a frame that is not in the domain of the scope is not possible, because of cross site scripting. That would not be secure (e.g. imagine inserting an iframe with Facebook and grabbing some data from the frame...).

Upvotes: 0

Related Questions