Nej, du skal bare huske at stjæle det hele ;o)
Dine funktioner:
function changeOptions(strSource,intIndex) {
if (strSource =="hus")
{
document.getElementById("beregningHus").selectedIndex = intIndex;
if(intIndex != 0) { intIndex += 2; }
document.getElementById("beregningStang").selectedIndex = intIndex;
document.getElementById("beregningFlag").selectedIndex = intIndex;
} else
{
if(intIndex < 2)
{
document.getElementById("beregningHus").selectedIndex = 0;
} else
{
document.getElementById("beregningHus").selectedIndex = intIndex - 2;
}
document.getElementById("beregningStang").selectedIndex = intIndex;
document.getElementById("beregningFlag").selectedIndex = intIndex;
}
}
function createFlagCalculator() {
var aryHus = new Array("3","3-4","4","5","5-6","6","7","7-8","8","9","10","11","11-12","12","13","14","15");
var aryStang = new Array("2","3","4","5","6","7","7,5","8","9","10","11","12","13","14","15","16","17","18","19");
var aryFlag = new Array("50 x 38","75 x 57","100 x 76","125 x 94","150 x 114","175 x 133","200 x 150","225 x 170","250 x 189","275 x 208","300 x 227","325 x 246","350 x 265","375 x 284","400 x 303","425 x 320","450 x 340","475 x 358","500 x 378");
var strHus = '<select id="beregningHus" onchange="changeOptions(\'hus\',this.selectedIndex);" onblur="changeOptions(\'hus\',this.selectedIndex);" style="margin:3px 0 6px;">';
strHus += '<option>Vælg</option>';
for (var i=0;i<aryHus.length;i++)
{
strHus += '<option>' + aryHus[i]
strHus += ' m';
strHus += '</option>';
}
strHus += '</select>';
var strStang = '<select id="beregningStang" onchange="changeOptions(\'stang\',this.selectedIndex);" onblur="changeOptions(\'stang\',this.selectedIndex);" style="margin:3px 0 6px;">';
strStang += '<option>Vælg</option>';
for (var j=0;j<aryStang.length;j++)
{
strStang += '<option>' + aryStang[j] + ' m</option>';
}
strStang += '</select>';
var strFlag = '<select id="beregningFlag" onchange="changeOptions(\'flag\',this.selectedIndex);" onblur="changeOptions(\'flag\',this.selectedIndex);" style="margin:3px 0 6px;">';
strFlag += '<option>Vælg</option>';
for (var k=0;k<aryFlag.length;k++)
{
strFlag += '<option>' + aryFlag[k] + ' cm</option>';
}
strFlag += '</select>';
return "Husets højde til kip:<br />" + strHus + "<br />Flagstangens højde:<br />" + strStang + "<br />Flagets mål:<br />" + strFlag;
}
</script>
Og der du udskriver dem:
<script type="text/javascript">
document.write(createFlagCalculator());
</script>