Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listbox, move up down, change priority

Status
Not open for further replies.

knuckle05

Programmer
Dec 17, 2001
247
CA
Hi All,

Not sure how to explain this...but I'd like to have a listbox with Items in it , where I could have an Up/Down arrow beside the box that would move the selected item up or down to change it's priority. Could anyone help me out with this, or at least get me started?

Thx!
 
try this...

<SCRIPT>
function outputList(ar, name, size) {
var strIDs = &quot;<SELECT SIZE=\&quot;&quot; + size + &quot;\&quot; NAME=\&quot;ro_lst&quot; + name + &quot;\&quot;>&quot;
var sel = &quot; SELECTED&quot;
for (var i=0;i<ar.length;i++) {
strIDs += &quot;<OPTION &quot; + sel + &quot; VALUE=\&quot;&quot; + ar[0] + &quot;\&quot;>&quot; + ar[1]
sel = &quot;&quot;
}
strIDs+=&quot;</SELECT>&quot;
strIDs+=&quot;<INPUT NAME=\&quot;&quot; + name + &quot;\&quot; TYPE=hidden>&quot;
return strIDs
}

function outputButton(bDir,name,val) {
return &quot;<INPUT TYPE=button VALUE=\&quot;&quot; + val + &quot;\&quot; ONCLICK=\&quot;move(this.form,&quot; + bDir + &quot;,'&quot; + name + &quot;')\&quot;>&quot;
}

function move(f,bDir,sName) {
var el = f.elements[&quot;ro_lst&quot; + sName]
var idx = el.selectedIndex
if (idx==-1)
alert(&quot;You must first select the item to reorder.&quot;)
else {
var nxidx = idx+( bDir? -1 : 1)
if (nxidx<0) nxidx=el.length-1
if (nxidx>=el.length) nxidx=0
var oldVal = el[idx].value
var oldText = el[idx].text
el[idx].value = el[nxidx].value
el[idx].text = el[nxidx].text
el[nxidx].value = oldVal
el[nxidx].text = oldText
el.selectedIndex = nxidx
}
}

</SCRIPT>
<FORM>
<SCRIPT>
var arrList = new Array()
arrList[0] = new Array(&quot;1&quot;,&quot;Test Item 1&quot;)
arrList[1] = new Array(&quot;2&quot;,&quot;Test Item 2&quot;)
arrList[2] = new Array(&quot;3&quot;,&quot;Test Item 3&quot;)
arrList[3] = new Array(&quot;4&quot;,&quot;Test Item 4&quot;)
arrList[4] = new Array(&quot;5&quot;,&quot;Test Item 5&quot;)
arrList[5] = new Array(&quot;6&quot;,&quot;Test Item 6&quot;)

document.write(outputButton(true,&quot;test&quot;,&quot;Move Up&quot;) + &quot;<BR>&quot;)
document.write(outputList(arrList,&quot;test&quot;,10) + &quot;<BR>&quot;)
document.write(outputButton(false,&quot;test&quot;,&quot;Move Down&quot;))
</SCRIPT>
<BR>
</FORM>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top