?
Solved

Pass variables to a iframe form

Posted on 2008-11-11
5
Medium Priority
?
590 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:Sam Cohen
  • 3
5 Comments
 
LVL 15

Expert Comment

by:quincydude
ID: 22936586
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
 
LVL 17

Expert Comment

by:HuyBD
ID: 22936592
You can use javascript with prefix parent
e.g
parent.frame1.document.forms[0].name.value="";
0
 
LVL 15

Accepted Solution

by:
quincydude earned 900 total points
ID: 22936614
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
 
LVL 8

Author Comment

by:Sam Cohen
ID: 22936626
So is it something like this:
<?php
$fname="Sam"
?>

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

0
 
LVL 15

Expert Comment

by:quincydude
ID: 22936663
You have to set a name for the iframe tag as in my code and replace the frame1 in your code with it.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question