?
Solved

communication between two php pages

Posted on 2006-06-13
3
Medium Priority
?
421 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 16892741
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
ID: 16892791
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 2000 total points
ID: 16892825
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

777 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