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!

Syntax for CFSET within Javascript function

Status
Not open for further replies.

redherring917

Programmer
Dec 21, 2004
5
0
0
CA
Within a popup window, I want to use CFSET to set a ColdFusion variable to the value of a form field found in the opener window. The following grabs the value of the form field - a string - just fine and successfully stuffs it into the variable "checkbox_valueM", but I can't for the life of me come up with the correct syntax to set a ColdFusion variable to this value using CFSET. This iteration of my attempts returns the error "The value "" cannot be converted to a number".

<cfset selectedproducts_M = "">

<SCRIPT LANGUAGE="JavaScript">
<!--
var checkbox_valueM = "";
var checkbox_valueM = (window.opener.document.productsearch.selectedproducts_M.value);
<cfset selectedproducts_M = selectedproducts_M + checkbox_valueM>
// -->
</script>

I am humbled. Any help would be greatly appreciated.

Thanks.
 
you can't do it that way. if you're going to use variables from the parent you have to pass them as url variables.

in the parent when you open the page do something like this.


popUpWindow=window.open ("verupdate.cfm?var1="+forms[0].fieldName.value"&var2="+forms[0]fieldName2.value)

then in the pop up you would do
<cfset myCFVar1 = url.var1>
<cfset myCFVar2 = url.var2>



A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
You can't.

Javascript values can't be read by Cf.

The best you can do is this...

Code:
  <cfoutput><cfset selectedproducts_M = "">
  <SCRIPT LANGUAGE="JavaScript">
    <!--
      <cfif not isDefined("url.cbv_m")>
        var checkbox_valueM = (window.opener.document.productsearch.selectedproducts_M.value);
      window.location = '#listlast(cgi.script_name,"/")#?sp_m=#selectedproducts_M#&cbv_m=' + checkbox_valueM;
      <cfelse>
        <cfset selectedproducts_M = #url.sp_m# + #url.cbv_m#>
      </cfif>
    // -->
  </script></cfoutput>

This does the same thing as your code except that after setting the opener url, it redirects this window to the same url but with the value of the js appeneded to the url.

The cf checks for the existence of that value and reads the url variable.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Haha, that's the second time today bud.

You explained the theory and I wrote the code. The posts work well together.

An effort of bombmigit! lol.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Thanks to all. I "knew" this at one time...

I hate having to re-learn things that I obviously didn't learn quite well enough the first (second, third...) time.

Got to go a different route as the value of the variable I wanted to access, (really a comma delimited list), is too long to pass in the URL.

Thanks again.

 
Could potentially just be exposing my ignorance here, but that's never stopped me before...

If I use javascript to populate a hidden form field on my popup window with the value from my opener window, can I then reference the value of this hidden field on the popup window using ColdFusion?

Thanks.
 
Only through a form post from the pop up window...

IE you can fill a hidden variable with javascript and post the form and read the variables in the posted form with cf.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top