brownmetals
asked on
Popup Window to Pass Value to Parent Window On Close
Hi there.
I'm writing an ASP application using MS Access. I have a data entry form that prompts a user for an ID value from the database. I'm providing a lookup so that the user can:
1) click a lookup link - pops up new window that allows search
2) search by name and obtain the corresponding ID
3) click the ID to close the lookup window and automatically populate the ID box on the data entry form.
I'm not sure how to pass the ID value from the lookup pop up window into the text field on the data entry form. At the same time, I'll need the window to close when the ID link is clicked. Can someone please provide guidance and example code?
Thank you,
J
I'm writing an ASP application using MS Access. I have a data entry form that prompts a user for an ID value from the database. I'm providing a lookup so that the user can:
1) click a lookup link - pops up new window that allows search
2) search by name and obtain the corresponding ID
3) click the ID to close the lookup window and automatically populate the ID box on the data entry form.
I'm not sure how to pass the ID value from the lookup pop up window into the text field on the data entry form. At the same time, I'll need the window to close when the ID link is clicked. Can someone please provide guidance and example code?
Thank you,
J
ASKER
Wow! I didn't realize it was going to be that complicated (compared to what I had been looking at). I've been trying to get something like this to work.
<a href="javascript:window.op ener.docum ent.getEle mentById(" DonorID"). value = 1001;">1001</a>
Is something like this not the best approach? From the data entry form, the lookup is either going to be a DonorID or a SolicitorID. I can pass the correct field value (form element name) to the javascript via ASP.
The issue I'm having with the item above is that there's currently a syntax error when I execute it. I'm trying to figure that out right now.
<a href="javascript:window.op
Is something like this not the best approach? From the data entry form, the lookup is either going to be a DonorID or a SolicitorID. I can pass the correct field value (form element name) to the javascript via ASP.
The issue I'm having with the item above is that there's currently a syntax error when I execute it. I'm trying to figure that out right now.
I just copied and pasted from here back to testing and no problem.
It might be this function though at fault:
function openPopup(targetField){
var w = window.open('popup.htm','p opup','wid th=610,hei ght=550,sc rollbars=1 ');
w.targetField = targetField;
w.focus();
return false;
}
If you copy and paste that over the top of the other one, that may fix it.
Once you have the javascript in the head of the page the way to call it is very simple.
I have not used the method your suggesting but I know this works.
It might be this function though at fault:
function openPopup(targetField){
var w = window.open('popup.htm','p
w.targetField = targetField;
w.focus();
return false;
}
If you copy and paste that over the top of the other one, that may fix it.
Once you have the javascript in the head of the page the way to call it is very simple.
I have not used the method your suggesting but I know this works.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is just a combination of both of yours, but I think it'll work...
<script>
function changeFormValue(val) {
window.opener.document.get ElementByI d("DonorID ").value = val;
window.close();
}
</script>
<a href="javascript://" onclick="changeFormValue(1 001)">1001 </a>
If this doesn't work, what's the syntax error that you're getting, and on what line?
<script>
function changeFormValue(val) {
window.opener.document.get
window.close();
}
</script>
<a href="javascript://" onclick="changeFormValue(1
If this doesn't work, what's the syntax error that you're getting, and on what line?
ASKER
OK, I'm almost there. Here's the code I'm currently using.
<a href="javascript:window.op ener.formA ddItems.Do norID.valu e=1004;win dow.close; ">1004</a>
When I click the link, the pop up window stays open and shows [Object]. The value is passed correctly from the popup to the data entry form. I just need to figure out how to get the popup closed and we have a winning solution. Any suggestions?
<a href="javascript:window.op
When I click the link, the pop up window stays open and shows [Object]. The value is passed correctly from the popup to the data entry form. I just need to figure out how to get the popup closed and we have a winning solution. Any suggestions?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to both of you for your input.
ncoo - that solution was a little more complicated than I was hoping for, but your input definitely helped me get to the desired solution. Thanks again.
J
ncoo - that solution was a little more complicated than I was hoping for, but your input definitely helped me get to the desired solution. Thanks again.
J
In index.htm paste this code:
<html>
<head>
<script>
function openPopup(targetField){
var w = window.open('popup.htm','c
w.targetField = targetField; //create target field variable in popup window with the passed targetField as value
w.focus();
return false;
}
//callback function
function setTargetField(targetField
if (targetField){
targetField.value = returnvalue;
}
window.focus();
}</script>
</head>
<body>
<form name="theForm">
<input type="text" name="name1" /><a href="#" onclick="return openPopup(document.theForm
<input type="text" name="name2" /><a href="#" onclick="return openPopup(document.theForm
</form>
</body>
</html>
In popup.htm paste the following:
<html>
<head>
<script>
function returnValue(value){
if (opener && !opener.closed && opener.setTargetField){
opener.setTargetField(targ
}
window.close();
}
</script>
</head>
<body>
<a href="#" onclick="returnValue('moos
</body>
</html>
In the popup window you will notice the onclick="returnValue('moos