• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

javascript to cfscript

Participant ,
May 03, 2006 May 03, 2006

Copy link to clipboard

Copied

Hello Gurus
Wondering if this is possible?
(CFMX 5)

I have a cfscript function:
<cfscript>
function doSomething(thingToDo) {
return URLEncodedFormat(Encrypt(thingToDo,myKey));
}
</cfscript>

takes 'thingTodo', encrypts it with private key and then makes friendly to use over URLs.

Now I want to pass in a JS variable instead of a raw string, something like this:

<cfoutput>
<select name="selectObject" onchange="javascript:location.href='somepage.cfm?#doSomething(this.value)#'">
<option value = "option1">Option 1
<option value = "option2">Option 2
</select>
</cfoutput>

so that thepage forwards to:
somepage.cfm?with_encrypted_js_variable_here

Is there a way to do this?
I have no hair left, so any pointers in the right direction appreciated

Jam
TOPICS
Advanced techniques

Views

2.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
May 03, 2006 May 03, 2006
Not sure if this is what your looking for but... how about this?

Note: if you want to encrypt the values on the fly you'll need to encode ( or encrypt ) through javaScript. I beieve the cold fusion and javaScript are processed and run at different times.

<cfscript>
myKey = 'test';
function doSomething(thingToDo) {
return URLEncodedFormat(Encrypt(thingToDo,myKey));
}
</cfscript>

<script language="javascript">
function loadURL(str) { self.location.href = 'somepage.cfm?' + str; }
</script>

<cfo...

Votes

Translate

Translate
Contributor ,
May 03, 2006 May 03, 2006

Copy link to clipboard

Copied

Couldn't you just get rid of the CFScript function and on your onchange do:
location.href="somepage.cfm?#UrlEncodedFormat(Encrypt(thingtodo,myKey))#

Or, I can't remember if this is the correct syntax, but set a variable equal to your function call
and append that to your url:

<CFSET EncString = doSomething()>
location.href="somepage.cfm?#EncString#

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 03, 2006 May 03, 2006

Copy link to clipboard

Copied

Not sure if this is what your looking for but... how about this?

Note: if you want to encrypt the values on the fly you'll need to encode ( or encrypt ) through javaScript. I beieve the cold fusion and javaScript are processed and run at different times.

<cfscript>
myKey = 'test';
function doSomething(thingToDo) {
return URLEncodedFormat(Encrypt(thingToDo,myKey));
}
</cfscript>

<script language="javascript">
function loadURL(str) { self.location.href = 'somepage.cfm?' + str; }
</script>

<cfoutput>
<select name="selectObject" onchange="loadURL(this.value)">
<option value = "#doSomething('option1')#">Option 1 </option>
<option value = "#doSomething('option2')#">Option 2 </option>
</select>
</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 03, 2006 May 03, 2006

Copy link to clipboard

Copied

Thanks guys - some good responses.
Just to clear up the typo at the top of my post : (CFMX or 5)

I'm gonna try both ideas in the morning so should reply early afternoon (GMT)

Art first glance:
james - i think the cf code gets processed first so I'm gonna place the js function at the point it's called and play around there.
cfpb - this looks possible. My problem is I was trying to eval the js var while inside a cf evaluate (urghhh) but your solution places the call on the option value (which incidentally is produced via cfloop). I cant believe i didn't think of this!

P

thanks for your help and i'll report back later..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 04, 2006 May 04, 2006

Copy link to clipboard

Copied

LATEST
cfbp - excellent! Your suggestion worked fine (even on the fly!)
Thanks for all your help

Jam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation