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

Why does my Javascript pass the incorrect URL variables? 1

Status
Not open for further replies.

johnhig

MIS
Jun 25, 2007
54
US
Good Morning,

I have this Javascript that opens a popup window. The popup window is a form and I am trying to carry 2 url variables and then output them on the form fields. Now the form opens up, but it brings over the incorrect variables

See below:

Here is the Javascript that lives inside a cfoutput tag
<SCRIPT language="JavaScript" TYPE="text/javascript">
function Inquiry()
{
window.name = 'MainWindow';
window.open("sendinquiry.cfm?machineID=#machineID#&unit_num=#unit_num#","displayWindow","width=700,height=600,toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes");
}
</SCRIPT>

Here is my link

<A HREF="javascript: Inquiry()">Send Inquiry</A>

Now an example of what happens is when I click on the Send Inquiry link, it is for Unit 1481, but when I look on the Send Inquiry form, it is display Unit 1876.

Now when I place it normally without the Javascript the code works and it displays the correct variables.

<A HREF="sendinquiry.cfm?machineID=#machineID#&unit_num=#unit_num#">Send Inquiry</A>

Thanks John
 
have you got any other declarations of the page for "unit_num"?

I don't know your application, but I'd suggest passing the variables into the JS, from within your code. so your code would look something like:

Code:
<script>
function Inquiry(unitNum,MachineID) {
  window.name = 'MainWindow';
  window.open("sendinquiry.cfm?machineID=" + MachineID + "&unit_num=" + unitNum + ","displayWindow","width=700,height=600,toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes");
}
</script>

<cfoutput query="abc">
  <a href="javascript:Inquiry(#abc.unit_num#, #abc.machine_id#)">Send Enquiry</a>
</cfoutput>

Hope this helps!

Tony
 
Thanks Tony,

That worked. Can you explain to me why Javascript could not recognized the variables when presented like the following?

function Inquiry()
{
window.name = 'MainWindow';
window.open("sendinquiry.cfm?machineID=#machineID#&unit_num=#unit_num#","displayWindow","width=700,height=600,toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes");
}
 
without seeing the rest of the code it would be hard to say. my guess would be that 1876 is the first item within your query so cf is finding the variable unit_num within the query and getting the first value. within your code i guess you have a loop or something like that, which is moving to the value you are expecting

did you have the javascript surrounded with cfoutput's?

hope this helps!

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top