Skip to main content
Inspiring
Mar 25, 2013 6:04 PM UTC
Question

on change

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

This topic is closed to new replies. Start a new post to keep the conversation going.

2 replies

Legend
Mar 29, 2013 4:36 PM UTC

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
BKBK
Community Expert
Community Expert
Mar 29, 2013 1:47 PM UTC

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