Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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.