Pass variables to a iframe form

Is there anyway to let say.
I have a page with vars define:
$fname="Jon";
$lname="Doe";
$email="john.doe@nothing.com";

and i have a button and a Iframe on the same page anf in the iframe shows any site where is says;
enter you first name, last name, email address in form fields

Is there anyway, if after i click the button, transfer the vars to the form fields?
The form fields are firstname, lastname, email

LVL 8
Sam CohenConsultant to Digital/DeveloperAsked:
Who is Participating?
 
quincydudeCommented:
You can do something like this though
<html>
<body>
 
<iframe src="somepage.html" name="myiframe"></iframe>
 
 
<input type=button value="go" onclick="document.myiframe.formname.fieldname.value='test';"/>
</body>
</html>

Open in new window

0
 
quincydudeCommented:
Do you mean getting php variables?
It's impossible for javascript to read php variables unless you write them to the html and store them as inputs manually.
0
 
HuyBDCommented:
You can use javascript with prefix parent
e.g
parent.frame1.document.forms[0].name.value="";
0
 
Sam CohenConsultant to Digital/DeveloperAuthor Commented:
So is it something like this:
<?php
$fname="Sam"
?>

<script>
function Onsubmit()
{
parent.frame1.document.forms[0].name.value="<?php $fname; ?>";
}
</script>

0
 
quincydudeCommented:
You have to set a name for the iframe tag as in my code and replace the frame1 in your code with it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.