here you go...

Create a Hidden form field thus :

<input type="hidden" name="linkorderlist" value="">




<!--- select box script, this will allow the user to reorder the list as and
when required --->
<script type="text/javascript">
<!--    

// NOTE : linkList is your select list, you could use the argument, but I
cant be arsed.

function moveEmLinks(direction,listname) {      

        if (listname == 'select2') {
                dfr = document.forms[0].linkList;
        }
        
        boxLen = dfr.length;
        currentItem = dfr.selectedIndex;
        
        if ((direction == 'up') && (currentItem > 0)) {         
                //reorder the text
                selText = dfr.options[currentItem].text;
                swpText = dfr.options[currentItem - 1].text;
                
                // reorder the value
                selValue = dfr.options[currentItem].value;
                swpValue = dfr.options[currentItem - 1].value;
                
                //reorder the text
                dfr.options[currentItem - 1].text = selText;
                dfr.options[currentItem].text     = swpText;
                
                // reorder the value
                dfr.options[currentItem - 1].value = selValue;
                dfr.options[currentItem].value    = swpValue;

                dfr.selectedIndex = currentItem - 1;
                // writeList();                         
                                
        } else if ((direction == 'down') && (currentItem < boxLen - 1) &&
(currentItem != -1)) {          
                selText = dfr.options[currentItem].text;
                swpText = dfr.options[currentItem + 1].text;
                
                // reorder the value
                selValue = dfr.options[currentItem].value;
                swpValue = dfr.options[currentItem + 1].value;
                
                //reorder the text
                dfr.options[currentItem + 1].text = selText;
                dfr.options[currentItem].text     = swpText;
                
                //reorder the value
                dfr.options[currentItem + 1].value = selValue;
                dfr.options[currentItem].value    = swpValue;
                
                dfr.selectedIndex = currentItem + 1;                    
                // writeList();
                
        } else if (currentItem == -1) {         
                 alert("One Link must be selected before it can be
reordered.");
                
        } else {}       
}


function writeList() {  
        alertText = "";
        
        // these ensure the length is always declared
        dfr = document.forms[0].linkList;
        boxLen = dfr.length;
                                        
        for (i=0;i<boxLen;i++) {        
                // value does not work as the list is effectively unchanged
                alertText = alertText + dfr.options[i].value+ ",";

        }               
        
         //alert(alertText);
         document.forms[0].linkorderlist.value = alertText;

}
        
//-->
</script>


Call it : href="javascript:moveEmLinks('up','linkList');"

or href="javascript:moveEmLinks('down','linkList');"
 

Same procedure are usual for submitting : you will have to select all and
then submit it.




-----Original Message-----
From: Dave Phipps [mailto:[EMAIL PROTECTED]
Sent: 29 September 2003 14:09
To: ColdFusion User group
Subject: [ cf-dev ] Select Box Reorder


Hi,

I have the following javascript which basically allows a select list to be 
reordered.  The original JS place the reordered list into a query string 
but I want to place it into a hidden form field.  I can get the hidden 
field to populate but it never changes the order when then select box is 
changed:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function move(index,to) {
var list = document.navOrder.list;
var total = list.options.length-1;
if (index == -1) return false;
if (to == +1 && index == total) return false;
if (to == -1 && index == 0) return false;
var items = new Array;
var values = new Array;
for (i = total; i >= 0; i--) {
items[i] = list.options[i].text;
values[i] = list.options[i].value;
}
for (i = total; i >= 0; i--) {
if (index == i) {
list.options[i + to] = new Option(items[i],values[i + to], 0, 1);
list.options[i] = new Option(items[i + to], values[i]);
i--;
}
else {
list.options[i] = new Option(items[i], values[i]);
    }

}
list.focus();
}
function submitForm() {
var list = document.navOrder.list;
var menuids = "";
var theList = "";
for (i = 0; i <= list.options.length-1; i++) {
theList += list.options[i].value;
menuids += list.options[i].value;
// a "," only BETWEEN the items, so not at the end
if (i != list.options.length-1) theList += ",";
if (i != list.options.length-1) menuids += ",";
}
document.navOrder.menuids.value = menuids;
document.navOrder.submit();
}
//  End -->
</script>

Anyone help with getting the reorder list into a hidden field?

Cheers

Dave


-- 
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]

-- 
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]

Reply via email to