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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why is <cflocation> keeping JavaScript from executing

Status
Not open for further replies.

LyndonOHRC

Programmer
Sep 8, 2005
603
US
I have a form where the action page is a popup. I'm doing some processing and then using a cflocation tag to present the results in the child window.

The javascript I’m trying to use changes a value on the parent window using getElementById.

If I comment out the cflocation tag on the child window the process works great, however, if I populate the child with cflocation the javascript seems to never run as the parent window does not get modified.

Thank for any assistance.

Parent Window:
Code:
<form name="Cards" id="Cards" method="post" action="PrintCard.cfm" target="_blank">
<input name="PageNumber" type="Hidden" value="#i#">
Sample Number: <input name="BarCode" size="10" value="#GetCard.BarCode#"><br>
Horse: <input name="Horse" size="20" maxlength="50" value="#GetCard.Horse#"><br>
<div align="center"><input type="Submit" value="Print/Save Card">&nbsp;<span id="Saved#i#" style="color: red;"></span></div>

Action Page:
Code:
<cfoutput>
	<cfif Trim(Form.WitnessName) gt '' and Trim(Form.WitnessBy) gt '' and Trim(Form.SampledBy) gt ''>
		<script language="JavaScript" type="text/javascript">
			objDiv=window.opener.document.getElementById('Saved#Form.PageNumber#');
			objDiv.innerHTML='Saved';
		</script>
	</cfif>
</cfoutput>

Write form fields to database....

<cflocation url="ReceiptForm.cfm">

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Afaik, that's what is supposed to happen.

Cflocation "stops execution of the current page and opens a ColdFusion page or HTML file."

In essence, CF runs the server-side code (cfml) then sends a redirect header to the browser. IIRC it only sends the header, not any of the client-side javascript/html code from the "Action Page". As an alternative, you could use javascript to redirect to the "ReceiptForm.cfm" page.
 
Sorry dumb question, I should have thought that through better before posting.

In my situation I think my best bet is the onsubmit event on the form.

If I understand that event correctly, the DOM will have the user entered data in the form elements and would then process my action page as usual won't it?

All I'm trying to do is place a text string on the form page if three of the text elements have data.

Thanks

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Not a dumb question. Truthfully I didn't understand how cflocation operated when I first started using it.

If I'm understanding correctly, yes you could use onSubmit. Though technically you'd be displaying "Saved" before the action page finished processing. So if an error occurred in the popup, the main page would still show "Saved".

Another option is to pass a url parameter to ReceiptForm.cfm and have that page call the javascript code depending on the value of the url parameter. But either way would work.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top