Hallo,
Aber so geht es auch nicht:
jau, weil noch einige Fehler drinstecken
<head>
<script type="text/javascript">
<!--
function add() {
Es gibt Namenskonfklikte, da Du auch ein Formularfeld namens add hast, benenne die Funktion in z.B. addOption um.
NeuerEintrag = new Option(document.form.alle.value,document.form.alle.value,false,true);
document.form.auswahl.options[document.form.auswahl.length] = NeuerEintrag;
document.form.alle.value = "";
form ist eine JavaScript-Eigenschaft, da gibt es ebenfalls Konflikte, bennene dein Formular um in z.B. myForm, natürlich dann auch überall document.myForm... ändern
}
function del() {
genau wie bei add(), umbenennen in z.B. delOption
document.form.auswahl.options[document.form.auswahl.length-1] = null;
}
//-->
</script>
</head>
<body>
<form name="form" method="post" action="">
Formularnamen ändern
<select name="alle" size="5" multiple>
<option>a</option>
<option>b</option>
<option>c</option>
<option>d</option>
<option>e</option>
hier mußt Du den Einträgen einen Value zuweisen, z.B. <option value="a">a</option>
</select>
<input type="button" name="add" value="hinzufügen" onClick="add()">
<input type="button" name="del" value="löschen" onClick="del()">
Funktionsnamen analog oben ändern
<select name="auswahl" size="5" multiple>
<option>dfg</option>
</select>
</form>
</body>
nun sollte es funktionieren
Wenn Du die gesamte Liste löschen willst:
function delOption()
{
for(var i=document.myForm.auswahl.length;i>0;i--) {
document.myForm.auswahl.options[i-1] = null;
}
}
HTH Markus