Jeg vil gerne kunne flytte de forskellige options op og ned, men ved ikke hvordan jeg skal konstrurer dette, så kunne godt tænke mig lidt hjælp med det.
Er det ikke lidt som normal sortering Du kan finde det markerede elements position. Hvis der klikkes på op så skal det bytte plads med elementet på positionen minus een vel? Kopier det første ned i bunden Kopier det andet ind på det førstes plads Kopier første tilbage på det andets plads og sæt den midlertidige til null
måske noget ligende det her --- function op() { var nr = document.dbListForm.dbList.selectedIndex; var indhold = document.dbListForm.dbList.options[nr].value var indhold2 = document.dbListForm.dbList.options[nr-1].value document.dbListForm.dbList.options[nr].value = indhold2 document.dbListForm.dbList.options[nr-1].value = indhold1 }
function op() { var nr = document.dbListForm.dbList.selectedIndex; var indhold1 = document.dbListForm.dbList.options[nr].value; var indhold2 = document.dbListForm.dbList.options[nr-1].value; document.dbListForm.dbList.options[nr].value = indhold2; document.dbListForm.dbList.options[nr-1].value = indhold1; }
Den retunere ingen fejl, men der sker intet. Skal det ikke også laves til en Option først ?
hvad så med: ------ function op() { var valgt = document.dbListForm.dbList.options[nr] var oppe = document.dbListForm.dbList.options[nr-1] document.dbListForm.dbList.options[nr] = oppe document.dbListForm.dbList.options[nr-1] = valgt } --- mon det kan bytte dem helt om
jamen jeg kom vist også til at slette den linje i sidste indlæg function op() { var nr = document.dbListForm.dbList.selectedIndex; var valgt = document.dbListForm.dbList.options[nr] var oppe = document.dbListForm.dbList.options[nr-1] document.dbListForm.dbList.options[nr] = oppe document.dbListForm.dbList.options[nr-1] = valgt }
sådan her...virker hos mig:o) --- function op() { var nr = document.dbListForm.dbList.selectedIndex; var valgt = document.dbListForm.dbList.options[nr].value var oppe = document.dbListForm.dbList.options[nr-1].value document.dbListForm.dbList.options[nr] = new Option(oppe); document.dbListForm.dbList.options[nr-1] = new Option(valgt); }
-- og jeg kom til at tænke på, om det ikke var smart at bruge removeChild til operationen, og det fungerer perfekt (men jeg kunne ikke dy mig for at implementere den fulde funktionalitet !-)
<script type="text/javascript"> function move(elm,dir){ if(typeof elm == 'string'); elm = document.getElementById(elm); var num = elm.selectedIndex; if(num == -1){ alert('No selection'); return; } if(dir=='up' && num==0 || dir=='down' && num==(elm.length-1))return; if(dir=='add'){ var txt = prompt('Text for the option','Text'); var val = prompt('Value for the option','Value'); if(txt == "" && val == "" || txt == 'Text' && val == 'Value'){ alert('You must supply at least a value or a text !-)'); return; } if(txt == "" || txt == 'Text') txt = val; if(val == "" || val == 'Value') val = txt; var opt = new Option(txt,val); elm.insertBefore(opt,elm.options[num]); opt.text = txt; return; } var opt = elm.removeChild(elm.options[num]); if(dir=='remove')return; if(dir=='up') elm.insertBefore(opt,elm.options[num-1]); else elm.insertBefore(opt,elm.options[num+1]); } </script>
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.