Link to home
Start Free TrialLog in
Avatar of traport
traport

asked on

Javascript - passing a value to parent window in a href and closing the window

In this coldfusion loop
<cfloop query="qry_getProjInfo">
 <tr>
<td><cfoutput><a href="">#proj_id#</cfoutput></td>
</tr>
 </cfloop>

Open in new window


I would like the href to contain this functionality (below) for each link in the loop so that when selected the pop-up closes and the input field "charge_number" is populated.

window.opener.document.getElementById("charge_number").value = '#proj_id#';
window.close();

Open in new window


I can't seem to write it correctly. Any help would be greatly appreciated.
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

Well, I don't know coldfusion at all, but if you copied-pasted your HTML+coldfusion code, then, first of all, you must ensure to close the <a> tag.

<td><cfoutput><a href="">#proj_id#</cfoutput></td>
must be
<td><cfoutput><a href="">#proj_id#</a></cfoutput></td>
Avatar of traport
traport

ASKER

Thanks...

Now... do you know Javascript at all?
Oh, yes, I know javascript.

Your javascript code seems correct. Does your code do something? The 'charge_number' field is updated in any way, or it remains unchanged?

Try using window.parent or window.top instead of window.opener.

Hope that helps.
Avatar of traport

ASKER

I haven't called the JavaScript in the href yet. This is what I'm not sure how to do. i.e. if I were to make the javascript I listed in my first block of code a function, how would I call it in the href. Sorry if I'm being unclear.
Avatar of traport

ASKER

For example, I'm trying this:
<cfoutput>
<cfloop query="qry_getProjInfo">
<script>
function passID(){
window.opener.document.getElementById("charge_number").value = '#proj_id#';
window.close();
}
</script>
                   
<tr>
<td><a href="javascript:void(0);" onClick="passID(#proj_id#)">#proj_id#</a></td>
</tr>
</cfloop>
</cfoutput>

Open in new window


And it does nothing. :(
ASKER CERTIFIED SOLUTION
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of traport

ASKER

Thank you so much for your help...

This is showing as having the correct ID to pass, but it is not passing it and closing the window...

<tr>
<td><a href="javascript:passID(0290278.001.012)">0290278.001.012</a></td>
</tr>

Open in new window


This is the code from you I used:

<script>
function passID(theID) {
	window.opener.document.getElementById("charge_number").value = theID;
	window.close();
	}
</script>
<cfoutput>
<cfloop query="qry_getProjInfo">
                <tr>
                 <td><a href="javascript:passID(#proj_id#)">#proj_id#</a></td>
                  </tr>
</cfloop>
</cfoutput>

Open in new window


The other one isn't firing it off and closing it either. I'm stumped. Thanks for sticking with me.
Avatar of traport

ASKER

No... disregard! Your second one worked perfectly. I'd copied it incorrectly. You are my hero!

Thank you.
Avatar of traport

ASKER

Thank you.
Avatar of traport

ASKER

Oh no! I thought it was still RolandDeschain helping me out. I didn't notice it was a second name. I'm so sorry RolandDeschain... I'd have given you points simply for how long you hung in there with me. I'm very sorry. Is there any way I can modify my points?

Thanks for your help mplungjan!
Don't worry, mplungjan did the hard work, I only started with a general guidelines.

Happy programming.
Hmm... assisted solution... :P
Avatar of traport

ASKER

I'm sorry I offended you. Thank you for your help.
No offence - I should perhaps have asked the mods to handle this instead wearing several hats ;)