• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

reset selectedIndexes

var i = 0 ;
            while( true )
            {
                  var teamASel = document.getElementById( 'MasterSelectA' + i ) ;
                  if( teamASel )
                        teamASel.selectedIndex = 0 ;
                  i++ ;
            }

whats wrong?
0
ellandrd
Asked:
ellandrd
1 Solution
 
TimYatesCommented:
Try this:

<HTML>
  <HEAD>
  <script type="text/javascript">

     function updateAllSlaveADropDowns( selected ) {
          var i = 1 ;
          while( true )
          {
            var aSel = document.getElementById( 'MasterSelectA' + i ) ;
            if( aSel )
              aSel.selectedIndex = selected ;
            else
              break ;
            i++ ;
          }
     }

     function updateAllSlaveBDropDowns( selected ) {
          var i = 1 ;
          while( true )
          {
            var aSel = document.getElementById( 'MasterSelectB' + i ) ;
            if( aSel )
              aSel.selectedIndex = selected ;
            else
              break ;
            i++ ;
          }
     }

     function resetSelects()
     {
       document.getElementById( 'MasterSelectA0' ).selectedIndex = 0 ;
       document.getElementById( 'MasterSelectB0' ).selectedIndex = 0 ;
       updateAllSlaveADropDowns( 0 ) ;
       updateAllSlaveBDropDowns( 0 ) ;
     }
  </script>
  </HEAD>
  <BODY onload="resetSelects()">
<table>
<tr>
     <td><select id="MasterSelectA0" onchange="updateAllSlaveADropDowns( this.selectedIndex )">
          <option>red</option>
          <option>green</option>
          <option>yellow</option></select>
     </td>
     <td><select id="MasterSelectB0" onchange="updateAllSlaveBDropDowns( this.selectedIndex )">
          <option>apples</option>
          <option>oranges</option>
          <option>grapes</option></select>
     </td>
</tr>
<script type="text/javascript">
<!--
var table = '';

for (j = 1; j < 7; j++)
{
     table += '<tr>';
     table += '<td><select id="MasterSelectA' + j + '"><option>red</option><option>green</option><option>yellow</option></select></td>';
     table += '<td><select id="MasterSelectB' + j +

'"><option>apples</option><option>oranges</option><option>grapes</option></select></td>';
     table += '</tr>';
}

document.write(table);

//-->
</script>
</table>
  </BODY>
</HTML>
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now