Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Using JavaScript To Call PHP Database Routines Between Windows
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.

[Page 1]  [Page 2]  


Comments:
How to select multiple valve from the dropdowDevendra Singh Sengar11/06/05 08:59
I understood clearlyArunmohan07/29/05 20:54
more usefull functionsEd van den Berg07/29/05 17:39
very confusinghabeeb12/06/04 15:44
very confusinghabeeb12/06/04 15:44
RE: Not clear Jobin Augustine08/09/04 07:13
RE: Not clear Jobin Augustine08/09/04 05:08
Not clear Francesco05/10/04 06:58
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.