Skip to main content
January 22, 2009
Question

ColdFusion and HTML Select

  • January 22, 2009
  • 1 reply
  • 488 views
Hello Everyone,

Is it possible to print the selected value of a drop down menu in Coldfusion?

<select name="dropdown>
<option value="1">1</option>
<option value="2">2</option>
</select>

If I select 1, I want to print 1 using cfoutput. Is this possible?

Thanks.
    This topic has been closed for replies.

    1 reply

    Inspiring
    January 22, 2009
    what do you mean by "print"? "print" where and when?
    if you are asking about displaying selected value on the page, then:

    a) if you want to display it AFTER the form has been submitted, then
    yes, you can use <cfoutput> to do that:
    <cfoutput>#form.name_attribute_of_your_select_tag#</cfoutput>

    b) if you want to display it BEFORE the form has been submitted, then
    you need to use javascript to do it (since CF runs on the SERVER and has
    no idea about what user has selected in the form until the form has been
    submitted). the simplest thing to do will be to add an ONCHANGE event to
    your <select> element with a little js script to display selected value
    in some other page element (a DIV, P, SPAN or TD will work nicely for this):

    <select ...
    onchange="document.getElementById('showvalue').innerHTML=this.value">
    ...
    </select>

    <div id="showvalue"></div>

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