javascript - Coldfusion AJAX checkboxes - post form data via jQuery or cfajaxproxy? -
ok, cf/ajax newbie here. i"m building out basic database-driven inventory checklist that, each item, displays:
- category
- stock number (id)
- item name
- picture of item
- color
- a checkbox (whether or not it's in stock - default "0")
i'm using cflayoutareas separate inventory collapsible accordion, each category in own section. goal have simple checklist "grays out" each item check off item , updates database , retains position in current accordion / list. inventory lists can long, 200+ items, quest have done cleanly ajax.
i have semi-working crude since relies on post/reload each check. know there's simple , elegant way code ajax haven't been able cobble various cfajax / bind / etc examples out there. perhaps jquery here? not sure. advice or direction appreciated.
here's sloppy version of have far:
to update database , reload list:
<cfif whatschecked neq ""> <cftransaction> <cfquery name="updatechecks" datasource="#application.dsn#"> update inventorychecklist set checked = "1" id in (<cfqueryparam value="#form.whatschecked#" cfsqltype="cf_sql_varchar" list="true">) </cfquery> <cfquery name="updatechecks0" datasource="#application.dsn#"> update inventorychecklist set checked = "0" id not in (<cfqueryparam value="#form.whatschecked#" cfsqltype="cf_sql_varchar" list="true">) </cfquery> </cftransaction>
<cfquery name="loadinventory" datasource="#application.dsn#"> select * inventorychecklist accountnumber = <cfqueryparam value="#session.accountnumber#" cfsqltype="cf_sql_varchar"> order category
form in body (posts itself,) loop through inventory (per category group)and display items / checkboxes, , gray out tr if it's been checked off:
<cfform name="mainform" action="checklist.cfm" method="post"> <cflayout name="mainchecklist" type="accordion" width="640"> <cfoutput query="loadinventory" group="category"> <cflayoutarea title="#category#, qty:#totalcount#" align="left"> category: #category#" <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td>stock number (id)</td> <td>item name</td> <td>item picture</td> <td>color</td> <td>in stock?</td> </tr> <cfoutput> <!--- if item checked off, gray out row ---> <cfif "#loadinventory.checked#" eq 1> <tr bgcolor="##333333"> <cfelse> <tr> </cfif> <td>#id#</td> <td>#loadinventory.itemname#</td> <td><img src="images/#loadinventory.category#/#loadinventory.item#.jpg"></td> <td>#loadinventory.color#</td> <td> <input type="checkbox" name="whatschecked" value="#id#" <cfif "#loadinventory.checked#" eq 1>checked="checked"</cfif> onclick="this.form.submit();"> </td> </tr> </cfoutput> </table> </cflayoutarea> </cfoutput>
Comments
Post a Comment