• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Participant ,
Sep 01, 2017 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>

Views

1.2K

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
community guidelines

correct answers 1 Correct answer

Advocate , Sep 04, 2017 Sep 04, 2017

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)

Votes

Translate

Translate
Advocate ,
Sep 04, 2017 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)

Votes

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
community guidelines
Participant ,
Sep 04, 2017 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?

Votes

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
community guidelines
LEGEND ,
Sep 05, 2017 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,

^ _ ^

Votes

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
community guidelines
Participant ,
Sep 05, 2017 Sep 05, 2017

Copy link to clipboard

Copied

LATEST

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

Votes

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
community guidelines
Resources
Documentation