House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

dynamic radio button submission

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Tuan
04/08/2003 09:52 PM

Ok, let's say I created a radio box dynamically from a query.  Something similar to : <form action="blah blah"> <table border="0">   <tr>     <td> </td>     <td>NUMBER</td>     <td>NAME</td>     <td>APPROVE</td>     <td>DISAPPROVE</td>     <td>REPOPEN</td>   </tr>   <cfoutput query="qry_num_info">   <input type="hidden" name="num" value="#num#">   <tr>     <td> </td>     <td>#num#</td>     <td>#name#</td>     <td><input type="Radio" value="approve" name="choice"></td>     <td><input type="Radio" value="disapprove" name="choice"></td>     <td><input type="Radio" value="reopen" name="choice"></td>   </tr>   </cfoutput>   <tr>     <td><br><br><br><br></td>   </tr>   <tr>     <td align="right" colspan="3"><input type="reset" value="Clear"></td>     <td align="left" colspan="3"><input type="submit" value="Finish"></td>   </tr> </table> </form> So the radio boxes are dependent upon the query.  How can I get the radio box to work correctly with this and how can I insert this info into a database?  The problem is the name attribute are the same for the radio input field because they're created dynamically by the query.  So there can be 1 or 3 or any number of rows with these radio boxes.  I hope I made my problem clear.  I apologize if its not.  

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ian Skinner
04/09/2003 12:02 AM

You need to create unique names for each of your radio sets.  Something like this may help.     <td><input type="Radio" value="approve" name="#name#"></td>     <td><input type="Radio" value="disapprove" name="#name#"></td>     <td><input type="Radio" value="reopen" name="#name#"></td> This will create one radio control for each row, no matter how many (as long as all names are unique). If the names aren't unique then you may want to use #num# or whatever the key of your record set is. Then in your action script you will have a form[name] key with a value of approve|disapprove|reopen for each radio set. Ian Skinner Web Programmer Sierra Outdoor Recreation www.SierraOutdoorReceation.com <http://www.SierraOutdoorReceation.com>   _____ I've stopped 2,871 spam messages. You can too! Get your free, safe spam protection at http://www.cloudmark.com/spamnetsig/} Ok, let's say I created a radio box dynamically from a query.  Something similar to : <form action="blah blah"> <table border="0">   <tr>     <td> </td>     <td>NUMBER</td>     <td>NAME</td>     <td>APPROVE</td>     <td>DISAPPROVE</td>     <td>REPOPEN</td>   </tr>   <cfoutput query="qry_num_info">   <input type="hidden" name="num" value="#num#">   <tr>     <td> </td>     <td>#num#</td>     <td>#name#</td>     <td><input type="Radio" value="approve" name="choice"></td>     <td><input type="Radio" value="disapprove" name="choice"></td>     <td><input type="Radio" value="reopen" name="choice"></td>   </tr>   </cfoutput>   <tr>     <td><br><br><br><br></td>   </tr>   <tr>     <td align="right" colspan="3"><input type="reset" value="Clear"></td>     <td align="left" colspan="3"><input type="submit" value="Finish"></td>   </tr> </table> </form> So the radio boxes are dependent upon the query.  How can I get the radio box to work correctly with this and how can I insert this info into a database?  The problem is the name attribute are the same for the radio input field because they're created dynamically by the query.  So there can be 1 or 3 or any number of rows with these radio boxes.  I hope I made my problem clear.  I apologize if its not.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Tuan Tran
04/09/2003 01:17 PM

How would i then create an insert query to insert these dynamically created radio fields?  Like say the query return 3 records so theres 3 rows of "NUM (some unique #)", "NAME(some name)", approve(dynamically created radio), disapprove(dynamically created radio) and reopen(dynamically created radio).  How can I submit those fields to the database.  Can you please show me a SQL insert statemat that would insert these dynamically named radio inputs.

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Douglas.Knudsen
04/08/2003 11:19 PM

name them in a unique, well semi-unique, way.  Something like this td><input type="Radio" value="approve" name="choice#qry_num_info.currentrow#"></td>     <td><input type="Radio" value="disapprove" name="choice#qry_num_info.currentrow#"></td>     <td><input type="Radio" value="reopen" name="choice#qry_num_info.currentrow#"></td> YMMV on the scheme for numbering them.  Keep in mind that when you build dynamic forms like this you may want to keep track of which row of data was updated so you do not have to run updates on say 150 rows when only 5 rows were changed.   Think hidden inputs, a boolean value, and a small JavaScript function for this... Doug ----- Excess quoted text cut - see Original Post for more -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
S. Isaac Dealey
04/09/2003 03:40 PM

Depends how the radio buttons are named... <cfquery name="rs" ...> select * from blah </cfquery> <cfoutput query="rs">   <div nowrap>     #rs.id# #rs.name#     <input type="radio" name="approved" value="#rs.id#">     <input type="radio" name="declined" value="#rs.id#">     <input type="radio" name="open" value="#rs.id#"> </cfoutput> next page <cfloop index="x" list="approve,decline,open">   <cfif structkeyexists(form,x)>     <cfquery ...>       UPDATE blah SET status = '#x#' WHERE id IN       <cfqueryparam value="#form[x]#" type="integer" list="true">     </cfquery>   </cfif> </cfloop> ----- Excess quoted text cut - see Original Post for more ----- s. isaac dealey                954-776-0046 new epoch                      http://www.turnkey.to lead architect, tapestry cms   http://products.turnkey.to tapestry api is opensource     http://www.turnkey.to/tapi certified advanced coldfusion 5 developer http://www.macromedia.com/v1/handlers/index.cfm?ID=21816

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Tuan
04/10/2003 11:29 PM

I can't seem to get this to work.  I tried the code you provided below, but I can't get it to work.  Can you explain what the code is actually doing and where the #x#, and #form[x# came from.   Depends how the radio buttons are named... <cfquery name="rs" ...> select * from blah </cfquery> <cfoutput query="rs">   <div nowrap>     #rs.id# #rs.name#     <input type="radio" name="approved" value="#rs.id#">     <input type="radio" name="declined" value="#rs.id#">     <input type="radio" name="open" value="#rs.id#"> </cfoutput> next page <cfloop index="x" list="approve,decline,open">   <cfif structkeyexists(form,x)>     <cfquery ...>       UPDATE blah SET status = '#x#' WHERE id IN       <cfqueryparam value="#form[x]#" type="integer" list="true">     </cfquery>   </cfif> </cfloop> ----- Excess quoted text cut - see Original Post for more ----- http://www.houseoffusion.com/cf_lists/uns >         ubscribe.cfm?user=633.558.4 s. isaac dealey                954-776-0046 new epoch                      http://www.turnkey.to lead architect, tapestry cms   http://products.turnkey.to tapestry api is opensource     http://www.turnkey.to/tapi certified advanced coldfusion 5 developer http://www.macromedia.com/v1/handlers/index.cfm?ID=21816

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
S. Isaac Dealey
04/11/2003 12:08 AM

the x and form[x] variables are on the page following the form submission. X comes from the loop <cfloop index="x" list="approve,decline,open"> which means that on each iteration of the loop, x will be equal to "approve", "decline" or "open". Which means form[x] will be form.approve, form.decline or form.open. <cfif structkeyexists(form,x)> ensures that at least one radio button with the given name was selected on the previous page before attempting the update. If so it should then update all of the items for which that radio button was selected with the given update statement. Actually I left out a queryparam -- it should say SET status = <cfqueryparam value="#x#" cfsqltype="cf_sql_varchar"> where id in etc... hth ----- Excess quoted text cut - see Original Post for more ----- s. isaac dealey                954-776-0046 new epoch                      http://www.turnkey.to lead architect, tapestry cms   http://products.turnkey.to tapestry api is opensource     http://www.turnkey.to/tapi certified advanced coldfusion 5 developer http://www.macromedia.com/v1/handlers/index.cfm?ID=21816

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Jason Wagstaff
04/11/2003 12:39 PM

maybe i am assuming this, but are you creating a list of items that need approve, decline, or open set to them? how about something like this for your form.... <cfoutput query="qItem"> <p>#qItem.Name# <input name="status_#qItemID#" type="radio" value="open" checked="checked">Open <input name="status_#qItemID#" type="radio" value="approved">Approved <input name="status_#qItemID#" type="radio" value="declined">Declined</p> </cfoutput> <input type="hidden" name="IDlst" value="#ValueList(qItem.ids)#"> <input type="submit"> than on your action page..... <cfloop list="#form.IDlst#" index="x">   <cfquery>   update blah set     status = <cfqueryparam value="#form['status_#x#']#">    where id = <cfqueryparam value="#x#">   </cfquery> </cfloop> i can't actually try that code out... but i have used the notation of form["foo_#x#"] manytimes and it works well hope that is what you are looking for jason --- "S. Isaac Dealey" <info@turnkey.to> wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Tuan
04/14/2003 10:11 PM

I was able to get it to work using information you guys provided me.  I apologize for not responding earlier.  I've been busy at work.  Thanks again to all those who helped. maybe i am assuming this, but are you creating a list of items that need approve, decline, or open set to them? how about something like this for your form.... <cfoutput query="qItem"> <p>#qItem.Name# <input name="status_#qItemID#" type="radio" value="open" checked="checked">Open <input name="status_#qItemID#" type="radio" value="approved">Approved <input name="status_#qItemID#" type="radio" value="declined">Declined</p> </cfoutput> <input type="hidden" name="IDlst" value="#ValueList(qItem.ids)#"> <input type="submit"> than on your action page..... <cfloop list="#form.IDlst#" index="x">   <cfquery>   update blah set     status = <cfqueryparam value="#form['status_#x#']#">    where id = <cfqueryparam value="#x#">   </cfquery> </cfloop> i can't actually try that code out... but i have used the notation of form["foo_#x#"] manytimes and it works well hope that is what you are looking for jason --- "S. Isaac Dealey" <info@turnkey.to> wrote: ----- Excess quoted text cut - see Original Post for more ----- http://www.houseoffusion.com/cf_lists/uns ----- Excess quoted text cut - see Original Post for more -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
S. Isaac Dealey
04/11/2003 12:55 PM

My understanding was that these items were all of the same type (i.e. a list of articles with status and you want to set the status for them all). The only difference between what I suggested and what you suggested is that yours loops over individual items while mine loops over the status and sets all items for that status at one time, which is faster if not necessarily intuitively obvious. And I just realized I left out some parenthesis in the sql query and mangled the cfqueryparam tag -- and it might have made more sense the first time if I'd used "status" instead of "x" as the variable name. <cfloop index="status" list="approve,decline,open">   <cfif structkeyexists(form,status)>     <cfquery datasource="mydsn">       UPDATE blah SET status =       <cfqueryparam value="#status#"          cfsqltype="cf_sql_varchar">       WHERE id IN       (<cfqueryparam value="#form[status]#"          cfsqltype="cf_sql_integer" list="true">)     </cfquery>   </cfif> </cfloop> ----- Excess quoted text cut - see Original Post for more ----- s. isaac dealey                954-776-0046 new epoch                      http://www.turnkey.to lead architect, tapestry cms   http://products.turnkey.to tapestry api is opensource     http://www.turnkey.to/tapi certified advanced coldfusion 5 developer http://www.macromedia.com/v1/handlers/index.cfm?ID=21816


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

June 20, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
             1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30             

Designer, Developer and mobile workflow conference