Copy link to clipboard
Copied
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"/>
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
>>
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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==-
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Regarding: However, I cannot give the radio buttons a static name
Why not?
Copy link to clipboard
Copied
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">
Copy link to clipboard
Copied
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().
Copy link to clipboard
Copied
Oh that makes a lot sense, I will try this. Thank you very much for your help!!!
Copy link to clipboard
Copied
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>