McKirahan wrote:
"Nigel Greenwood" <nd*******@yahoo.co.uk> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
McKirahan wrote:
Here's a variation where one can rank their favorite colors.
Their first choice is placed at the top, then their next choice, etc.
Here's one that just moves 'em up & down. If IE would allow proper
DOM manipulation of option elements, you could just move the option
from one select to the other...
function moveOpt(selA)
{
var sOpt = selA.options[selA.options.selectedIndex];
selB.appendChild = sOpt.parentNode.removeChild(sOpt);
}
Here's one that just moves 'em up & down:
<script type="text/javascript">
function init(sel)
{
// Array of colours
var list = ["White","Red","Orange","Yellow","Green",
"Blue","Indigo","Violet","Grey","Black"];
for (var i=0, num=list.length; i<num; ++i){
sel.options[i] = new Option(list[i], list[i], false, false);
}
}
function moveOpt(sel, d)
{
// Set up and check selection/movement
var idxA = sel.options.selectedIndex;
var len = sel.options.length;
var idxB = idxA + d;
if (-1==idxA || 0>idxB || len==idxB) return;
// Swap element attributes
var xT = sel.options[idxA].text;
var xV = sel.options[idxA].value;
sel.options[idxA].text = sel.options[idxB].text;
sel.options[idxA].value = sel.options[idxA].value;
sel.options[idxB].text = xT;
sel.options[idxB].value = xV;
// re-select previous selected
sel.options[idxB].selected = true;
sel.options[idxA].selected = false;
}
window.onload = function() {
init(document.forms['form1'].s5);
}
<form action="" method="get" name="form1">
<table>
<tr>
<td>
<select name="s5" size="11" class="sel1"></select>
</td>
<td>
<input type="button" value="Move up" onclick="
moveOpt(this.form.s5,-1);
"><br>
<input type="button" value="Move down" onclick="
moveOpt(this.form.s5,1);
">
</td>
</tr>
--
Rob