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

cfselect onchange to set session variable

New Here ,
May 19, 2008 May 19, 2008

Copy link to clipboard

Copied

I'm trying to figure out how to take the select value from a cfselect and use it to set a session variable.

I've tried calling a cfscript function...no success.

I'm not using flash...and that's the only examples I could find.

Any ideas?
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
LEGEND ,
May 19, 2008 May 19, 2008

Copy link to clipboard

Copied

javascript = client-side
cf = server-side

the 2 do not meet unless you submit data to the server...

several options for you:
1) easy way: submit your form with the select's onchange event and
process the form data to set the session var
2) if you are on CF8 you can use the new cf ajax features like
cfajaxproxy to send data to a cfc
3) if you are not on CF8, you can employ rob gonda's ajaxCFC to achieve
similar functionality
4) use a js framework like jQuery which supports asynchronous requests
to send the selected value to a cfm/cfc

option 1) above will require page reload. other options can do it
asynchronously without reloading the page, but you better know your
javascript... and cf components...

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/

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
Explorer ,
May 19, 2008 May 19, 2008

Copy link to clipboard

Copied

LATEST
If you want to do it without using the built in ajax stuff, you can still roll your own. You'd need a hidden frame, like an iFrame set to 0 height and width, and a backend template the accept the information from the generated select box (I'll call this 'myVariableProcessor.cfm'). Name the hidden frame 'theProcessor' or something, and make sure your form has a name as well. In the javascript event of the CFSelect-generated select box, you need something like this: "Javascript:goSetMyVariable();". Then, in the same page, you'll need a javascript function something like this:

function goSetMyVariable(){
mySel = document.all.myForm.mySelectBox;
myVal = mySel.options[mySel.selectedIndex].value;
document.all.theProcessor.src='myVariableProcessor.cfm?newValue='+myVal;
}

...the upshot is, when the onChange event fires in your CFSelect box, you call a javascript function that grabs the relevent value out of the CFSelect, and then passes it to a processor template that updates your session variables. Do all this in a hidden frame, and it should remain invisible to the end user. I'd suggest at least using ssl for this, and checking authentication in the var processor, as there are some security issues associated with passing URL variables to alter session vars, but you get the idea.

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