Results 1 to 3 of 3

Thread: JS and the use of FOR

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Question 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;

  2. #2
    Junior Member phrodu's Avatar
    Join Date
    Dec 2002
    Location
    Telletubbie Land
    Posts
    18
    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>

  3. #3
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    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;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width