Copy link to clipboard
Copied
I have this code that outputs select lists of months and select lists of the dates (1-31)
The form loads OK and the months and dates are in the lists just fine.
But when I select a month and a date I want it to stay selected when I submit the form
So if I choose May 5 and click submit
I want it to look like this
But no matter what I select it always ends up January and 1
Here is the code
<tr>
<th>Choose Feed Date:</th>
<th align="left"> <select name="feed_date_m">
<cfloop index="m" from=1 to=12>
<option value="#m#" <cfif #form.feed_date_m# is "m">selected</cfif>>#monthasstring(m)# </option>
</cfloop>
</select>
<select name="feed_date_d">
<cfloop index="d" from=1 to=31>
<option value="#d#">#d# <cfif #feed_date_d# is "d">selected</cfif></option>
</cfloop>
</select></th>
</tr>
By doing <cfif #form.feed_date_m# is "m"> you are saying "Is the value of form.feed_date_m equal to the character "m".
It is not checking the loop index value.
You want to do something like this:
<cfif form.feed_date_m EQ m>
(You dont need the # in cfif)
Copy link to clipboard
Copied
By doing <cfif #form.feed_date_m# is "m"> you are saying "Is the value of form.feed_date_m equal to the character "m".
It is not checking the loop index value.
You want to do something like this:
<cfif form.feed_date_m EQ m>
(You dont need the # in cfif)
Copy link to clipboard
Copied
Some progress
THIS WORKS
<select name="feed_date_d">
<cfloop index="d" from=1 to=31>
<option value="#d#" <cfif form.feed_date_d EQ d>selected</cfif>>#d#</option>
</cfloop>
</select>
THIS DOESNT??
<select name="feed_date_m">
<cfloop index="m" from=1 to=12>
<option value="#m#" <cfif form.feed_date_m EQ m>selected</cfif>>#monthasstring(m)</option> <
</cfloop>
</select>
Any idea why the DATE works but the month doesn't?
Copy link to clipboard
Copied
If this code you provided is copied and pasted from your codeset and not manually typed in, then you need to add a hashtag to the end of #monthasstring(m)
HTH,
^ _ ^
Copy link to clipboard
Copied
Yes, I missed that for about an hour. Thank you