2016-04-07 4 views
1

Ich habe ein Formular im Tabellenformat erstellt. Ich möchte, dass das Eingabefeld innerhalb der Tabelle auf den nächsten Punkt fokussiert, sobald die maximale Länge erreicht ist. Ich habe jquery Code verwendet, aber es arbeitet nur mit Eingängen nicht mit td. Der Code ist unten:Google Formular speichern in Excel-Blatt

$(".inputs").keyup(function() { 
    var index = $('.inputs').index(this) + 1; 
    $('.inputs').eq(index).focus(); 
}); 

und der table HTML-Code:

<form> 
    <table> 

     <tr> 

      <td class="custom_header">First Name* </td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

      <td><input class="input" type="text" maxlength="1" required/></td> 

     </tr> 
    </table> 

</form> 

Und wie dieses Formular als Google-Formular einzureichen, da es so viele Eingänge hat?

+0

Was meinen Sie mit "google Form"? Sprechen Sie über das Formular, das mit der [Google Form App] (https://www.google.com/forms/about/) erstellt wurde? –

Antwort

0

Versuchen tabinex Attribut in <input /> zu verwenden. Im Anschluss arbeitet Beispiel:

<form> 
     <table> 
      <tbody> 
       <tr> 
        <td> 
         <input tabindex="0" class="input" type="text" maxlength="1" required/> 
        </td> 
        <td> 
         <input tabindex="1" class="input" type="text" maxlength="1" required/> 
        </td> 
        <td> 
         <input tabindex="2" class="input" type="text" maxlength="1" required/> 
        </td> 
        <td> 
         <input tabindex="3" class="input" type="text" maxlength="1" required/> 
        </td> 
        <td> 
         <input tabindex="4" class="input" type="text" maxlength="1" required/> 
        </td><br /> 
        <td> 
         <input tabindex="5" class="input" type="text" maxlength="1" required/> 
        </td> 
        <td> 
         <input tabindex="6" class="input" type="text" maxlength="1" required/> 
        </td> 
       </tr> 
      </tbody> 
     </table> 
    </form> 
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.3.min.js"></script> 
<script> 
    $(document).ready(function() { 
     $('.input').on('keyup', function(e) { 
      var input = $(this), 
      nextInput = $('input[tabindex="' + (Number(input.attr('tabindex')) + 1) + '"]'); 

      // If current input value is reached max limit and if there is any next input 
      // then it will make focus to it. 
      input.val().length == input.attr('maxlength') && nextInput.length && nextInput.focus() 
       }); 
       }); 
    </script> 
+0

Vielen Dank @Vikram kann dies funktioniert können Sie mir sagen, wie es in Google-Form verwenden. Ich meine, ich muss diese Felder in Excel-Tabelle über Google-Formular speichern. –

+0

@JyotiRawat, können Sie bitte im Detail erklären? was genau willst du erreichen? Teilen Sie die Geige Ihres Codes mit, um das Problem besser zu verstehen. – Vikram

+0

Ich habe Formular mit einem Grid-Layout (Tabellenformat) Ich möchte das Formular als Google-Formular verwenden, wo ich die vom Benutzer gefüllten Daten speichern kann, sollte in Excel-Tabelle gespeichert werden. Da ich so viele Eingabefelder habe, bekommt Tabindex einen Konflikt. In einigen Eingabefeldern funktioniert der von Ihnen angegebene Code und in einigen Eingabefeldern funktioniert er nicht. https://jsfiddle.net/jyotirawat/jgkvtbbj/ –