Shaun Mccran

My digital playground


Firefox helpfully caching forms and their values

Whilst building a form recently I hit a real noob stumbling block. I was trying to set a select value to selected if the value had previously been submitted, something like this:

view plain print about
1<cfset variables.prefix = "Mr,Mrs,Ms,Miss,Dr">
2                <select name="title" size="1" class="form-select">
3                    <option value="">Please select from</option>
4                    <cfloop list="#variables.prefix#" index="variables.index" delimiters=",">
5                        <option value="#variables.index#" <cfif attributes.title EQ #variables.index#> selected="yes" </cfif>>#variables.index#</option>
6                    </cfloop>
7                </select>

Pretty straight forward, you'll all agree. The issue comes in where I had entered selected="selected". This isn't the correct code for a select option.

Handily Firefox will cache the form structure and form data, so that when you refresh the page it just loads up the cached version. This is great if you coded it correctly, otherwise it happily serves you up your coding errors again. So don't refresh your forms in testing.

Add ?test=1 or something to make the request a new URL.

Henry Ho's Gravatar For HTML 4.01 , just use 'selected' in <option>

For XHTML, use 'selected="selected"' in <option></option>

If you're using populating <select> from a query object, give cfselect a look. <cfselect query="qList" selected="1,3,5,7,9"/>
# Posted By Henry Ho | 14/12/09 20:47
Back to top