|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Using Radio Buttons for an Outputted Query
I have an approval page where records are generated from a database query and with it, an approve box where the user can click yes or no (from a radio button) and then submit the form. Right now, I am only able to choose one radio button overall. So say for example if there are 3 records, the user can only pick a yes or no for one of them and not for each record. I would like to be able to select a yes or no for each record that is outputted. The code is as follows:
<form action ="msdsApproval.cfm" method="post" name="MSDS"> <table width="85%" border="1" cellpadding="3" cellspacing="0"> <tr> <td width="16%"><div align="center" class="style18 style19"><span style="font-weight: bold">Material</span></div></td> <td width="16%"><div align="center" class="style18 style19"><span style="font-weight: bold">Mfg</span></div></td> <td width="16%"><div align="center" class="style18 style19"><span style="font-weight: bold">IssueDate</span></div></td> <td width="16%"><div align="center" class="style18 style19"><span style="font-weight: bold">ShelfLife</span></div></td> <td width="16%"><div align="center" class="style18 style19"><span style="font-weight: bold">FirstAid</span></div></td> <td width="16%"><div align="center" class="style18 style19"><span style="font-weight: bold">Approve</span></div></td> </tr> <cfoutput query="pendingMSDS"> <tr> <td><span class="style7">#pendingMSDS.Material#</span></td> <td><span class="style7">#pendingMSDS.Mfg#</span></td> <td><span class="style7">#dateformat(pendingMSDS.IssueDate,'mm/dd/yyyy')#</span></td> <td><span class="style7">#pendingMSDS.ShelfLife#</span></td> <td><span class="style7">#pendingMSDS.FirstAid#</span></td> <td><span class="style7"><input type="radio" name="approve" value="Y">Yes</span><span class="style7"> <input type="radio" name="approve" value="N">No</span></td> </tr></cfoutput> </table> <input name="submit" type="submit" value="Submit Approval"> </form> |
|
#2
|
|||
|
|||
|
You need a unique name for each record's radio button. You could do something like this for the radio button:
<td><span class="style7"><input type="radio" name="approve_#pendingMSDS.currentRow#" value="Y">Yes</span><span class="style7"> <input type="radio" name="approve" value="N">No</span></td> So if the query generated 3 records, you'd have 3 radio buttons named approve_1, approve_2, and approve_3. If you have a "unique" value for each record that's being output (maybe "Material"?) you could use that instead of currentRow so that you know which radio button goes with which material. However you do it, on the action page you now will get an approval value for each record.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
Thanks it worked like a charm.
|
|
#4
|
|||
|
|||
|
Now that I have generated those approves with a unique name. How am I able to access them on my action page. Here is the code I am using and it errors.
<cfif not isDefined("Form.MSDS")> <cflocation url="msdsFacilityApproval.cfm"> </cfif> <cfquery name="pendingMSDS" datasource="MSDS"> SELECT MaterialId FROM materialView WHERE material='#Form.msds#' AND mfg = '#Form.Mfg#' </cfquery> <cfif Form.approve_#pendingMSDS.MaterialId# IS "Y"> <cfquery name="updateMSDS" datasource="MSDS"> UPDATE materialView SET FacilityApproval=1 </cfquery> </cfif> <cflocation url="msdsFacilityApproval.cfm"> |
|
#5
|
|||
|
|||
|
The problem is in your if statement. You're just evaluating the variable name, not the VALUE stored within the variable. Do something like this:
<cfif Form["approve_#pendingMSDS.MaterialId#"] IS "Y"> |
|
#6
|
|||
|
|||
|
That works when there is only one approval needed. However, if I have two or more, and if the user clicks yes to approve them, I get this error below which I have no idea what it means.
Element approve_ is undefined in a Java object of type class coldfusion.filter.FormScope referenced as |
|
#7
|
|||
|
|||
|
Try adding an isDefined check, like this:
<cfif isDefined( 'form.approve_#pendingMSDS.MaterialID#' ) and Form["approve_#pendingMSDS.MaterialId#"] IS "Y"> |
|
#8
|
|||
|
|||
|
That doesnt help. All that is happening now is that the error goes away but it just comes back to the same approval page and not doing anything. I think I need a cfloop to loop through each Id and then update if it is yes but am not sure how to do it. Would this work and if so would you know how to do it?
|
|
#9
|
|||
|
|||
|
Yes, I assumed you were already doing that. You'll need to loop through the form fields and perform the update for each applicable form field. You can get a list of the fields submitted from form.fieldList and loop over that, checking each one to see if it's one of the fields that you want to use to update the DB.
|
|
#10
|
|||
|
|||
|
Ok I think I got it. Thanks.
|
|
#11
|
|||
|
|||
|
Sorry to be so bothersome, but for some reason my code below which is for the action page is not working for two or more approvals. This is the error I get right now if two or more approvals are clicked: Parameter 1 of function SetVariable, which is now "", must be a syntactically valid variable name. The code is below.
<cfif not isDefined("Form.MSDS")> <cflocation url="msdsFacilityApproval.cfm"> </cfif> <cfquery name="pendingMSDS" datasource="****"> SELECT MaterialId FROM materialView WHERE material='#Form.msds#' AND mfg = '#Form.mfg#' </cfquery> <cfloop list="Form.MSDS" index="#pendingMSDS.MaterialId#"> <cfif isDefined('Form.approve_#pendingMSDS.MaterialId#') AND Form["approve_#pendingMSDS.MaterialId#"] IS "Y"> <cfquery name="updateMSDS" datasource="****"> UPDATE materialView SET FacilityApproval=1 WHERE materialId='#pendingMSDS.MaterialId#' </cfquery> </cfif> </cfloop> <cflocation url="msdsFacilityApproval.cfm"> Do you know what is wrong with it? |
|
#12
|
|||
|
|||
|
Your loop syntax is incorrect. The list attribute should be list or a variable that holds a list (ie #form.fieldList#) and the index should be an index name such as "i" or "thisFieldName".
You may need to move the query "pendingMSDS" inside the loop so that it runs for each of the approved materials. |
|
#13
|
|||
|
|||
|
Thanks, I finally got it to work!
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Using Radio Buttons for an Outputted Query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|