PHPBuilder - Using JavaScript To Call PHP Database Routines Between Windows Page 2



RSS Twitter
Articles Html

Using JavaScript To Call PHP Database Routines Between Windows - Page 2

by: Alan Gruskoff
|
March 23, 2004

Now, what I need to do is have the user open a second screen that selects a Contact, then posts that Contact ID back to the first screen. That's a good start, I also now want the first screen to go and do this read-and-post-back function that works nicely on it's own. To get this inter-window communication tied in, I will set this Javascript function to see if any change has been made to the value of the Contact ID and if so, call it's partner on the same page doContactID() to go and read-and-post-back for us.
function checkContactID() {
var ContactID = document.forms.Form1.ContactID.value;
var WasContactID = document.forms.Form1.WasContactID.value;
if (ContactID != WasContactID) {
doContactID();
}
}
Here's what makes this all work now that all my JavaScript functions are built in the first page. The second page, which is just a select list popup window will post the ContactID back to the first page AND tell the first page to do that nice read-and-post-back function, then close itself. The net result is the first page is now populated with the database read results based on the user's selection.
The second screen has anywhere within it's <Form> this button:
<input type="button" value="Select" onClick="doContact(this.form)">
When then user hits that button it does this:
<script language="javascript1.2">
function doContact(form) {
var ContactID = form.selectBox.options[form.selectBox.selectedIndex].value;
self.opener.document.forms['Form1'].ContactID.value = ContactID;
self.opener.window.checkContactID();
self.window.close();
}
</script>
Notice the self.opener... statements, that's what make the windows work together. Coming from a structured programming background, I was looking for straight down code, Web pages don't work that way. This is a way to get pages to act like "subroutines" and talk to each other.
Little smoke, lots of mirrors. Very useful.
About The Author:
Alan Gruskoff - Performant Systems, Sept. 2003. Alan is the lead developer at Performant Systems, a Linux / Database / Web design company in Pasadena CA, developers of the ExpoGrid System.

« Previous Page
1
|
2

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Alan Gruskoff

Comment:



Comment:

(Maximum characters: 1200). You have characters left.