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

setting a variable from select option value

Explorer ,
Sep 23, 2008 Sep 23, 2008
I'm having a hard time setting a variable from the value in my select, option (drop-down box value). Can someone give me some sample code to do that?
Thanks.
1.2K
Translate
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 ,
Sep 23, 2008 Sep 23, 2008
form.cfm
--------
<form action="action.cfm" method="post">
<select name="myCoolSelect">
<option value="foo" selected="selected">Joe Cool</option>
</select>
<input type="submit">
</form>


action.cfm
----------
<cfoutput>#form.myCoolSelect#</cfoutput>
Translate
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 ,
Sep 23, 2008 Sep 23, 2008
What kind of variable? What's it going to be used for?
Translate
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 ,
Sep 23, 2008 Sep 23, 2008
The option variable will be a URL. I want to use the variable in my action statement, as in <cfform action=the url from the select statement.
Translate
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 ,
Sep 23, 2008 Sep 23, 2008
<form name="form3" method="post" action="#dev#">
<select onChange="this.form.submit()" name="dev">
<option value="javascript:void(0)" selected>- Select -</option>
<option value="search-swdev.cfm">Approved Developers List</option>

My question is: How do I get "search-swdev.cfm" set as #dev# so that action will load that URL?
Translate
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 ,
Sep 24, 2008 Sep 24, 2008
> My question is: How do I get "search-swdev.cfm" set as #dev# so that action
> will load that URL?
>

Reading this and some of your replies.... I do not think this is a
ColdFusion problem. That looks like you are trying to create a
JavaScript jump list.

I have not done this in a long time since they have fallen out of favor
do to accessibilities issues.

You will need to create a JavaScript function that is called from the
select onChange event. This function will read the value of the
selected option, modify the form action to this value and then submit
the form.
Translate
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
Sep 25, 2008 Sep 25, 2008
LATEST
<select onChange="this.form.action = this.value;this.form.submit()" name="dev">

the above script might work.
Translate
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 ,
Sep 23, 2008 Sep 23, 2008
The simplest way is to submit to a page which reads that form field and forwards the user to the real page.
Translate
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 ,
Sep 24, 2008 Sep 24, 2008
How do I do that? Don't I still have to know the value of the option? How do I get that?
Translate
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 ,
Sep 24, 2008 Sep 24, 2008
quote:

Originally posted by: tgoold
How do I do that? Don't I still have to know the value of the option? How do I get that?

from the form variables.
Translate
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 ,
Sep 24, 2008 Sep 24, 2008
Is it like form.option.value?
Translate
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 ,
Sep 24, 2008 Sep 24, 2008
quote:

Originally posted by: tgoold
Is it like form.option.value?

No, that is javascript which you can use to see your form field values before you submit your form.

I was referring to form scope variables which you can process with cold fusion after the form is submitted.
Translate
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 ,
Sep 24, 2008 Sep 24, 2008
oh, ok. I'll give it a try. Thanks for your help.
Translate
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 ,
Sep 24, 2008 Sep 24, 2008
Thanks, Ian. I don't think I can do it without JavaScript either.
Translate
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