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

Dynamic Radio Button Group

New Here ,
Sep 10, 2010 Sep 10, 2010
I need to get the value of the radio button, if the user selected Y or 
N. The Field names are going to be dynamically generated from id's in
the database to form Radio Groups. The code below will not work, but you can
see what I trying to achieve, any ideas?


<cfif
isDefined('FORM.bnt2')>
   
<cfloop index="i" list="#form.fieldnames#">
       
<cfquery  name="accept" datasource="#request.dsn#">
            UPDATE opt SET
            f14 = '#evaluate(i)#'
            WHERE f4 = '#FORM.id#'
       
</cfquery>
   
</cfloop>
</cfif>                                                             

<cfform  name="frm2" id="form2" method="post" action="">
   
<cfinput type="radio" name="#f5#" value="y">
   
<cfinput type="radio" name="#f5#" value="n">
   
<cfinput type="hidden" name="id" value="#f4#" />
   
<cfinput name="bnt2" type="image" class="btn" src="images/accept.gif" value="Submit"/>
2.1K
Translate
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
Valorous Hero ,
Sep 10, 2010 Sep 10, 2010

The code below will not work

Can you elaborate on "will not work"? If you are receiving an error, can you post the full error message?

Translate
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
New Here ,
Sep 10, 2010 Sep 10, 2010

Thank you for your response, here is a little background on what I'm trying to achive.

The user will input their Id number then the accounts tied to this Id  number will be presented(radio buttons) . They could have 1 or even 10  accounts returned(radio buttons). I need to have them update their account to a Y, N or if empty do not enter a value. The  account Id is what makes up the radio groups. Now I need to know how to  loop through these radio buttons to see what they selected.

So when I say will not work, I mean I cannot get the value of the radio buttons to update the db.

Translate
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
Valorous Hero ,
Sep 10, 2010 Sep 10, 2010

>>

What is an example of the names #f5# and how does it relate to the "id" value #f4#?

In terms of basic form mechanics, nothing will be passed if neither button is selected. It does not look like you are forcing Y or N to be checked by default. So what do you want to happen if the user does not check either button?

-Leigh

Translate
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
New Here ,
Sep 10, 2010 Sep 10, 2010

The #f5# is the users accounts being generate from a Query...

<cfloop query="accountCheck" >
                    <cfoutput>
                     <tr>
                        <td width="225">****** #Left(f5,4)#  #f6#</td>
                      <td width="225">
                        <cfinput type="radio" name="#f5#" value="y">
                    
                      </td>
                      <td width="225"><cfinput type="radio" name="#f5#" value="n"></td>
                      </tr>
                   
                  </cfoutput>
                  </cfloop>
                  
                   
                  </table><br />
                 <cfoutput query="accountCheck" group="f4">
                   <cfinput type="hidden" name="id" value="#f4#" />
                 </cfoutput>
                  <cfinput name="bnt2" type="image" class="btn" src="images/accept.gif" value="x"  style="float:right;" />
                  </cfform>

The #f4# is telling me which user is upating these accounts, all of the fileds for #f5# are currently NULL the user needs to have the option

to not SELECT Y or N and leave that field NULL.

Translate
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
Valorous Hero ,
Sep 10, 2010 Sep 10, 2010

Umm.. I am not sure if you answered the questions

The purpose of the fields is clear.  But we need to know the values of #f5# and #f4#. That will tell us what form field names are being be generated, and ultimately .. how you might structure your UPDATE.

When processing form fields dynamically, the field names matter.  So without knowing the structure of the field names, it is very hard to advise you any further.

Message was edited by: -==cfSearching==-

Translate
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
New Here ,
Sep 10, 2010 Sep 10, 2010

The value #f4# will matchup to the users iD number in the db ex."25345". This information was gathered on Step1,

before this form, and which tell me which radio names to return on this form Step 2.

The name of #f5# is the users different accounts, however the value will be a Y or N, or left NULL that

will be used to upated #f14# that in shown in the Update Statement. Hope this make sense and ansers your question.

Translate
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 10, 2010 Sep 10, 2010

Couple of things.

First, array notation runs faster than evaluate:  the syntax is form["static part" & variable part]

Second, look at your data before trying to use it in a query.

Third, according to your code, the database is being updated.  However, it's being updated for every single form field.

Fourth, on your form, life is a lot simpler if you give every radio button the same name, but different values.

Translate
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
New Here ,
Sep 10, 2010 Sep 10, 2010

Hi Dan,

That is my problem I need to update only for the radio buttons and don't know how. However, I cannot give the radio buttons a static name

that would make this task a sinch if I could. The problem is I could have 1 radio group retuned or 10 radio groups returned,

in the case if the user has 10 accounts I need some way to return 10 different radio group names to make the Y N options

mutually exclusive.

Translate
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 10, 2010 Sep 10, 2010

Regarding:  However, I cannot give the radio buttons a static name

Why not?

Translate
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
New Here ,
Sep 10, 2010 Sep 10, 2010

Because I don't know if I will have 1 radio group or 10 radio groups.

If I try and give 20 radio buttons the same name I will not have 10 radio groups,

I will then have 20 radio buttons in 1 radio group.

1 Group Returned (Works Fine).

<cfinput type="radio" name="static name" value="y">

<cfinput type="radio" name="static name" value="n">

10 Radio Group Returned ( Now they are not mutually executive)

Instead of having 10 Radio Groups I have 1 Large Radio Group

Meaning I can only select "n" on 1 radio group instead of 10.

<cfinput type="radio" name="static name" value="y">

<cfinput type="radio" name="static name" value="n">

<cfinput type="radio" name="static name" value="y">

<cfinput type="radio" name="static name" value="n">

<cfinput type="radio" name="static name" value="y">

<cfinput type="radio" name="static name" value="n">

<cfinput type="radio" name="static name" value="y">

<cfinput type="radio" name="static name" value="n">

<cfinput type="radio" name="static name" value="y">

<cfinput type="radio" name="static name" value="n">

<cfinput type="radio" name="static name" value="y">

<cfinput type="radio" name="static name" value="n">

<cfinput type="radio" name="static name" value="y">

<cfinput type="radio" name="static name" value="n">

<cfinput type="radio" name="static name" value="y">

<cfinput type="radio" name="static name" value="n">

<cfinput type="radio" name="static name" value="y">

<cfinput type="radio" name="static name" value="n">

<cfinput type="radio" name="static name" value="y">

<cfinput type="radio" name="static name" value="n">

Translate
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
Valorous Hero ,
Sep 10, 2010 Sep 10, 2010

The typical approach is to assign a counter number to each set of fields, such as query.currentRow. So you end up with

staticName1

staticName2

staticName3

staticName4

...

By storing the total number of records in a hidden field, you can later use a from/to loop to extract each value using associative array notation:

form["staticName"& counter]

Though radio buttons only pass a value if they were checked. So you will need to verify the existence of those fields first, with something like structKeyExists().

Translate
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
New Here ,
Sep 10, 2010 Sep 10, 2010

Oh that makes a lot sense, I will try this. Thank you very much for your help!!!

Translate
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
New Here ,
Sep 11, 2010 Sep 11, 2010
LATEST

Thank you all for your help, here was my final solution.

<cfif isDefined("FORM.bnt2")>
<cfloop index="id" list="#form.listofids#" delimiters=",">
<cfquery  name="accept" datasource="#request.dsn#">
UPDATE opt SET
F14 = '#Evaluate("form.select_#id#")#'
WHERE f5 = '#id#'
</cfquery>
</cfloop>
</cfif>

<cfform  name="frm2" id="form2" method="post" action="">
<cfoutput query="accountCheck" >
<cfinput type="radio" name="select_#f5#" value="y" required="yes" validateat="onsubmit" message="A value of Yes or No is required.">
<cfinput type="radio" name="select_#f5#" value="n" required="yes" validateat="onsubmit" message="A value of Yes or No is required.">
<cfinput type="hidden" name="listofids" value="#ValueList(accountCheck.f5)#" >
</cfoutput>
<cfinput name="bnt2" type="image" class="btn" src="images/accept.gif" value="x"  style="float:right;" />
</cfform>

Translate
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