Solved

communication between two php pages

Posted on 2006-06-13
3
402 Views
Last Modified: 2011-10-03
Hi experts,

actually i am not sure is this a php question, or it's a javascript question...

for example, i have a page called form.php, basically it's a form asking for user's input

then i have another page called call.php, it contains a list of names....  what i want is that when a user clicked on the list of name in call.php, the value of that name will be passed into form.php, and form.php should be updated by itself ...    i saw this somewhere on the web actually, but i am not sure how to get this done, either via php or javascript?

thanks a lot!!

airok
0
Comment
Question by:airok
  • 2
3 Comments
 
LVL 49

Expert Comment

by:Roonaan
Comment Utility
You can use javascript to pass the value from call.php to form.php and then let the form in form.php submit itself to refresh the page. (You can also just refresh the page, but I expect you need to submit the form).

Are your pages within a frameset or do they have an opener/popup relationship?

-r-
0
 

Author Comment

by:airok
Comment Utility
it's a opener/popup relationship

do u have a example javascipt can let me take a look for reference?

i would like to know how to do this if it's a frameset too...  ;)
many thanks!!

sorry i am not familiar with javascript at all...
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 500 total points
Comment Utility
When call.php is the popup you can have this script:
[form.php]
<form name="mainForm">
  <input type="text"  name="callField" />
  <input type="button" onclick="window.open('call.php');" value="Load call.php" />
</form>
[call.php]
<script type="text/javascript">
function setFormField(field, value, submit) {
  frm = window.opener.document.forms.mainForm;
  frm.elements[field].value = value;
  if(submit) frm.submit();
}
</script>

<a href="javascript:setFormField('callField', 'Name 1', true);">Name 1</a><br/>
<a href="javascript:setFormField('callField', 'Name 2', true);">Name 2</a><br/>
<a href="javascript:setFormField('callField', 'Name 3', true);">Name 3</a><br/>
<a href="javascript:setFormField('callField', 'Name 4', true);">Name 4</a><br/>
<a href="javascript:setFormField('callField', 'Name 5', true);">Name 5</a><br/>
<a href="javascript:setFormField('callField', 'Name 6', true);">Name 6</a><br/>
<a href="javascript:setFormField('callField', 'Name 7', true);">Name 7</a><br/>

When you are having frames you only have to change the javascript:

<script type="text/javascript">
function setFormField(field, value, submit) {
  frm = parent.otherFrameName.document.forms.mainForm;
  frm.elements[field].value = value;
  if(submit) frm.submit();
}
</script>

Hope this helps,

-r-
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now