Skip to main content
Inspiring
October 19, 2021
Question

CFselect onchange

  • October 19, 2021
  • 2 replies
  • 1311 views

Hello,

 

I want to get the value of cfselect option whitout click submit. I see, we can use the OnChange Method but i can't recover the javascript value in Coldfusion.

 

Can you help me ? Thanks in advance.

    This topic has been closed for replies.

    2 replies

    Charlie Arehart
    Community Expert
    Community Expert
    October 20, 2021

    Cfselect simply creates a traditional select tag and its option tags. As such, you can obtain the value selected (without submit) using Javascript, and in a way that has nothing to do with coldfusion.

     

    I don't write js enough to readily offer specific code for you, but assuming no one else does, I'm pointing you in the direction you need to look (outside of coldfusion).

     

    If instead you feel this IS still somehow a cf question, please elaborate. 

    /Charlie (troubleshooter, carehart. org)
    ZNBAuthor
    Inspiring
    October 20, 2021

    Thank you for your quick reply. I am looking for a solution to retrieve this value. If I don't use javascript, I don't mind. Isn't there a solution built into Coldfusion to define a variable with an OnChange in a Select?

     

    In advance, thank you for your answer.

    Charlie Arehart
    Community Expert
    Community Expert
    October 21, 2021

    There is not. Again, cfselect builds html (select and option tags). It does not add javascript, it does not execute javascript. By default, it will only send the result back to CF when the form is submitted.

     

    But again YOU can add javascript to detect things in the client. The most that cfselect offers is that onchange attribute that you have mentioned. That is simply a placeholder for you to provide javascript. You have to write it. (I appreciate that you may not write js. You just need to look into it or find someone who will offer it.)

     

    This is just one of those things where the server-side CFML does not provide the kind of client-side power you want. You get that from js itself, or from js libraries that add such power, like jquery. BTW, CF provides jquery built-in, so you may be able to leverage that without even adding such a library...or you can add one, and your client-side request and js you write will be able leverage that. Hope that gets you closer to a solution.

    /Charlie (troubleshooter, carehart. org)
    ZNBAuthor
    Inspiring
    October 20, 2021

    Help