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

on change

Explorer ,
Mar 25, 2013 Mar 25, 2013

Hi,

what is wrong with this code since the drop down box is not changing to display the correct value.  It didn't highlighted the one i selected..
<cfoutput>
<cfif isDefined('form.code')>
    <cfset page.code = form.code />
</cfif>

<form action="#cgi.SCRIPT_NAME#" method="post" name="mycode">
<select name="code" required="yes" onchange="this.form.submit()">
        <option value=""><b>Select Customer</b></option>
        <option value="AB" <cfif isDefined('form.code')><cfif form.code eq "AB">selected</cfif></cfif>>AB- None</option>
        <option value="CD" <cfif isDefined('form.code')><cfif form.code eq "CD">selected</cfif></cfif>>CD- Deliver</option>
        </select>
</form>

<cfif isDefined('page.code')>
#code#
</cfif>
</cfoutput>

thanks

TOPICS
Getting started
625
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
Community Expert ,
Mar 29, 2013 Mar 29, 2013

It should work. In any case, you could improve slightly on the logic like this

<cfform name="mycode">

    <select name="code" required="yes" onchange="this.form.submit()">

        <option value="">Select Customer</option>

        <cfif isDefined('form.code')>

        <option value="AB" <cfif form.code eq "AB">selected</cfif>>AB- None</option>

        <option value="CD" <cfif form.code eq "CD">selected</cfif>>CD- Deliver</option>

        <cfelse>

        <option value="AB">AB- None</option>

        <option value="CD">CD- Deliver</option>

        </cfif>

    </select>

</cfform>

<cfif isDefined('form.code')>

    <cfoutput>#form.code#</cfoutput>

</cfif>

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
Advocate ,
Mar 29, 2013 Mar 29, 2013
LATEST

I don't see an obvious issue. It may be a caching issue on either the browser side or server side. Since we're showing possible code improvements, I would do the following:

<cfparam name="form.code" default="" />

<cfoutput>

<form action="#cgi.SCRIPT_NAME#" method="post" name="mycode">
<select name="code" required="yes" onchange="this.form.submit()">
<option value=""><b>Select Customer</b></option>
<option value="AB" <cfif form.code eq "AB">selected</cfif>>AB- None</option>
<option value="CD" <cfif form.code eq "CD">selected</cfif>>CD- Deliver</option>
</select>
</form>

#code#
</cfoutput>

I would also add jquery validation to require a selction by the user (assuming that it is a required field). But all the is off topic.

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