Select til select tar ikke med value
Jeg har funnet dette scriptet på via eksperten.Problemet er at det ikke virker når man legger det inn i en form. Ingen av verdiene i sel1 eller sel2 tas med:
Hva er feil?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>moveFromTo() - flyt options fra en selectbox til den anden</title>
<script type="text/javascript">
/**
* Moves the selected elements from a selectbox to another
* @param from the selectbox id where the elements are taken from
* @param to the selectbox id where the elemenents are moved to
*/
function moveFromTo(from,to) {
fromElm = document.getElementById(from);
toElm = document.getElementById(to);
var sletArr = new Array();
while (fromElm.selectedIndex != -1) {
toElm.options[toElm.length] = new Option(fromElm.options[fromElm.selectedIndex].text,fromElm.options[fromElm.selectedIndex].value);
fromElm.options[fromElm.selectedIndex] = null;
}
}
</script>
<style type="text/css">
</style>
</head>
<body>
<form name="MyForm" action="test.html" method="get">
<select multiple id="sel1" style="height:200px;width:100px">
<option value="val1">Value 1</option>
<option value="val2">Value 2</option>
<option value="val3">Value 3</option>
<option value="val4">Value 4</option>
<option value="val5">Value 5</option>
</select>
<input type="button" value=">>" onclick="moveFromTo('sel1','sel2');">
<input type="button" value="<<" onclick="moveFromTo('sel2','sel1');">
<select multiple style="height:200px;width:100px" id="sel2">
</select>
<br><br>
<input type="submit" value="send">
</form>
</body>
</html>
