Highlighted

Cant get "selected" to work when looping through months and dates

Participant ,
Sep 01, 2017

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.

Capture.PNG

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

c2.PNG

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)

Views

1.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Cant get "selected" to work when looping through months and dates

Participant ,
Sep 01, 2017

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.

Capture.PNG

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

c2.PNG

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)

Views

1.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 01, 2017 0
Advocate ,
Sep 04, 2017

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)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 04, 2017 0
Participant ,
Sep 04, 2017

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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 04, 2017 0
LEGEND ,
Sep 05, 2017

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,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 05, 2017 1
Participant ,
Sep 05, 2017

Copy link to clipboard

Copied

Yes, I missed that for about an hour. Thank you

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 05, 2017 0