Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add record to database getting id from another page

Status
Not open for further replies.

upplepop

IS-IT--Management
Jun 1, 2002
173
0
0
US
I have a page that allows a user to edit details about a company or agency. One of the things a user can do is add to a list of services an agency provides. However, the list of services is so extensive that I have made a separate page (as a pop-up) for users to search & navigate to the service they are looking for. But once the user finds the service they want, they should be able to click on a hyperlink to add that service to a table.

I am pretty new to Javascript, so I'm not sure how to proceed. I imagine that either:
1) The agency detail page needs to send the agency id number to the pop-up, keep it persistent while navigating to the service, and create a link that uses that ID to insert a record. OR...
2) have the pop-up hyperlink return the service ID to the agency detail page so the detail page can insert the record.

I am writing the page in ASP and using MS SQL 2000 as the database. If someone could help me with some generic code, I should be able to modify it to work on my site.

Thanks for your help.
 
When you call your popup page you can pass the agency ID number on the querystring.
Example:
Code:
function svcLookup(agencyID) {
  var url = "myfile.asp?service="+agencyID;
  svcWin = window.open(url,"","scrollbars=yes,menubar=yes,width=320,height=320,top=100,left=320,alwaysRaised=yes,location=0");
  svcWin.creator = self;
  svcWin = svcWin.focus() 
}

From your popup page you can alter the values on the original page.
Assume the original page has a hidden form field like this:
<input type="hidden" id="selectedService">

Then on your popup page when a service is selected execute a javascript function like this one:
Code:
function setSelection(whichService) 
{
  this.window.creator.document.getElementById('selectedService').value = whichService;
  window.close();
}

How you execute the above function depends on how your services page is setup. You will call the function and pass the value of the selection to it and that value will be written back to the hidden field on the main page then close the popup.

From there it is a matter of how you want to handle writing the data to the database. You might have a submit button to submit the change in which case you have the service already stored in the hidden field for the next page to read.


It's hard to think outside the box when I'm trapped in a cubicle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top