You should look at the Sortable class as part of script.aculo.us - definitely a 
much better approach than the old up/down arrows!

Best,
Brian

> In my form I am trying to implement Up/Down movement and store the 
> changes into 
> database without refreshing the page. In order to accomplish this I 
> would like 
> tio use Ajax . 
> So that what I came up with 
> Hidden variable: 
 
> <cfoutput> <input type="hidden" Name="FieldsSave" 
> id="FieldsSave"></cfoutput>
> 2 buttons 
 
> <input type="button" id="moveUp" name="moveUp" value="MoveUp" 
> onclick="javascript:Field_up(document.category.categorylist,document.
> category.FieldsSave)">
> 
> <input type="button" id="moveDown" name="moveDown" value="moveDown" 
> onclick="javascript:Field_down(document.category.categorylist,document.
> category.FieldsSave)">
      
> 
> The functions assosiated withing the function 
> function Field_up(lst,lstSave) {
> var i = lst.selectedIndex;
> if (i>0) Field_swap(lst,i,i-1);
> SetFields(lst,lstSave);
> }
> function Field_down(lst,lstSave) {
> var i = lst.selectedIndex;
> if (i<lst.length-1) Field_swap(lst,i+1,i);
> SetFields(lst,lstSave);
> 
> }
> function Field_swap(lst,i,j) {
> var t = '';
> t = lst.options[i].text; lst.options[i].text = lst.options[j].text; 
> lst.options[j].text = t;
> t = lst.options[i].value; lst.options[i].value = lst.options[j].value; 
> 
> lst.options[j].value = t;
> t = lst.options[i].selected; lst.options[i].selected = lst.options[j].
> selected; 
> lst.options[j].selected = t;
> t = lst.options[i].defaultSelected; lst.options[i].defaultSelected = 
> lst.options[j].defaultSelected; lst.options[j].defaultSelected = t;
> //lst.focus();
> 
> } 
 
> function SetFields(lst,lstSave) {
> var t;
> lstSave.value="";
> for (t=0;t<=lst.length-1;t++)
> lstSave.value+=String(lst.options[t].value)+",";
> //lst.focus();
> if (lstSave.value.length>0)
> lstSave.value=lstSave.value.slice(0,-1);
> } 
> 
> The CF server file:
> <cfparam name="form.FieldsSave" default="">
> <cfif isDefined("form.moveUp") or isDefined("form.moveDown")>
> <cfset Order=1>
> <cfloop list="#Form.FieldsSave#" index="field">
> <cfquery name="SetOrder" datasource="XXXXXXX">
> UPDATE trnAcademicProgramCategory
> SET categorySort = #Order#
> WHERE  categoryId=#field# and schoolCode='#session.schoolcode#'
> </cfquery>
> <cfset Order = Order + 1>
> </cfloop>
> </cfif> 


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Download the latest ColdFusion 8 utilities including Report Builder,
plug-ins for Eclipse and Dreamweaver updates.
http;//www.adobe.com/cfusion/entitlement/index.cfm?e=labs%5adobecf8%5Fbeta

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:292982
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to