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> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Get the answers you are looking for on the ColdFusion Labs
Forum direct from active programmers and developers.
http://www.adobe.com/cfusion/webforums/forum/categories.cfm?forumid-72&catid=648

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:292969
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