Omskrivning af Population boks
HejsaEr der nogen der kan hjælpe mig med at omskrive nedenstående kode, så den skriver værdierne ud i et <input type="text"> felt istedet for Select felter, og når man vælger fra firstChoice (select) skriver den både ud i seccondChoice og thirdChoice på samme tid
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var arrItems1 = new Array();
var arrItemsGrp1 = new Array();
arrItems1[1] = "Truck";
arrItemsGrp1[1] = 1;
arrItems1[2] = "Boat";
arrItemsGrp1[2] = 2;
arrItems1[3] = "Planes";
arrItemsGrp1[3] = 3;
var arrItems2 = new Array();
var arrItemsGrp2 = new Array();
arrItems2[1] = "747";
arrItemsGrp2[1] = 1
arrItems2[2] = "Kolb Flyer";
arrItemsGrp2[2] = 2
arrItems2[3] = "Schwietzer Glider";
arrItemsGrp2[3] = 3
function selectChange(control, controlToPopulate, ItemArray, GroupArray)
{
var myEle ;
var x ;
// Empty the second drop down box of any choices
for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
if (control.name == "firstChoice") {
// Empty the third drop down box of any choices
for (var q=myChoices.thirdChoice.options.length;q>=0;q--) myChoices.thirdChoice.options[q] = null;
}
// ADD Default Choice - in case there are no values
myEle = document.createElement("option") ;
myEle.value = 0 ;
myEle.text = "[SELECT]" ;
controlToPopulate.add(myEle) ;
// Now loop through the array of individual items
// Any containing the same child id are added to
// the second dropdown box
for ( x = 0 ; x < ItemArray.length ; x++ )
{
if ( GroupArray[x] == control.value )
{
myEle = document.createElement("option") ;
myEle.value = x ;
myEle.text = ItemArray[x] ;
controlToPopulate.add(myEle) ;
}
}
}
// End -->
</script>
</HEAD>
<BODY>
<form name=myChoices>
<table align="center">
<tr>
<td>
<SELECT id=firstChoice name=firstChoice onchange="selectChange(this, myChoices.secondChoice, arrItems1, arrItemsGrp1);">
<option value=0 SELECTED>[SELECT]</option>
<option value=1>Land</option>
<option value=2>Sea</option>
<option value=3>Air</option>
</SELECT>
</TD><TD>
<SELECT id=secondChoice name=secondChoice onchange="selectChange(this, myChoices.thirdChoice, arrItems2, arrItemsGrp2);">
</SELECT>
<SELECT id=thirdChoice name=thirdChoice>
</SELECT>
</TD>
</TR>
</TABLE>
</form>
</body>
</html>
Håber der er en der kan hjælpe mig, for jeg er ikke særlig hård til JavaScript :-)
Mvh
Stig
