opa: getElementsByName

Beitrag lesen

Ausschnitt aus dem HTML-Formular:

<tr>
         <td>Anzahl der Piktogramme:</td>
         <td>
            <select id="icon" onChange="chg_Icon();">
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5" selected>5</option>
               <option value="6">6</option>
               <option value="7">7</option>
               <option value="8">8</option>
               <option value="9">9</option>
               <option value="10">10</option>
            </select>
         </td>
      </tr>
      <tr name="icon_row" style="display: table-row;"><td>Piktogramm 1:</td><td>Bilddatei: <input type="file" name="icon[]" size="30"> / Text: <input name="piktotext[]" size="30" maxlength="150"></td></tr>
      <tr name="icon_row" style="display: table-row;"><td>Piktogramm 2:</td><td>Bilddatei: <input type="file" name="icon[]" size="30"> / Text: <input name="piktotext[]" size="30" maxlength="150"></td></tr>
      <tr name="icon_row" style="display: table-row;"><td>Piktogramm 3:</td><td>Bilddatei: <input type="file" name="icon[]" size="30"> / Text: <input name="piktotext[]" size="30" maxlength="150"></td></tr>
      <tr name="icon_row" style="display: table-row;"><td>Piktogramm 4:</td><td>Bilddatei: <input type="file" name="icon[]" size="30"> / Text: <input name="piktotext[]" size="30" maxlength="150"></td></tr>
      <tr name="icon_row" style="display: table-row;"><td>Piktogramm 5:</td><td>Bilddatei: <input type="file" name="icon[]" size="30"> / Text: <input name="piktotext[]" size="30" maxlength="150"></td></tr>
      <tr name="icon_row" style="display: none;"><td>Piktogramm 6:</td><td>Bilddatei: <input type="file" name="icon[]" size="30"> / Text: <input name="piktotext[]" size="30" maxlength="150"></td></tr>
      <tr name="icon_row" style="display: none;"><td>Piktogramm 7:</td><td>Bilddatei: <input type="file" name="icon[]" size="30"> / Text: <input name="piktotext[]" size="30" maxlength="150"></td></tr>
      <tr name="icon_row" style="display: none;"><td>Piktogramm 8:</td><td>Bilddatei: <input type="file" name="icon[]" size="30"> / Text: <input name="piktotext[]" size="30" maxlength="150"></td></tr>
      <tr name="icon_row" style="display: none;"><td>Piktogramm 9:</td><td>Bilddatei: <input type="file" name="icon[]" size="30"> / Text: <input name="piktotext[]" size="30" maxlength="150"></td></tr>
      <tr name="icon_row" style="display: none;"><td>Piktogramm 10:</td><td>Bilddatei: <input type="file" name="icon[]" size="30"> / Text: <input name="piktotext[]" size="30" maxlength="150"></td></tr>

Die Funktion chg_Icon():

function chg_Icon()
{
   n = document.forms[1].elements["icon"].value - 1;

for(i=0;i<=9;i++)
   { document.getElementsByName("icon_row")[i].style.display = "none"; }

for(i=0;i<=n;i++)
   { document.getElementsByName("icon_row")[i].style.display = "table-row"; }
}