-
JS and the use of FOR
I wish to write the code below using FOR:
Code:
document.form1.komp1[document.form1.komp1.selectedIndex].value = 1;
document.form1.komp2[document.form1.komp2.selectedIndex].value = 1;
document.form1.komp3[document.form1.komp3.selectedIndex].value = 1;
.....
How can I do that using FOR?
Code:
for (i=1;i<4;i++){
document.form1.elements('komp'+i)[document.form1.elements('komp'+i).selectedIndex].value = 1;
-
You could try something like:
<script language="javascript">
<!--
document.write('<script language="javascript">');
for(x=1;x<=3;x++){
document.write('document.form1.komp'+x+'[document.form1.komp'+x+'.selectedIndex].value = 1;');
}
document.write('</script>');
//-->
</script>
-
I think the example in the first post should probably be something like this:
Code:
for (i=1;i<4;i++){
document.form1.elements['komp'+i].options[document.form1.elements['komp'+i].selectedIndex].value = 1;