Uncaught TypeError: Cannot read property 'element' undefined beim Absenden

Ich habe ein HTML-div-Ausgabe mit PHP die, wenn Sie auf "Abschicken" geklickt wird, sollte das Formular abschicken und Feuer eine JS-Funktion. Wenn Sie eingereicht wird, der JS-Konsole in Chrome gibt mir die folgende Fehlermeldung:

Uncaught TypeError: Cannot read property 'element' undefined

Meine HTML - (eingewickelt in ein PHP heredoc)

<div id="tab5" class="tab">
     <div id="reopen_case_form">
        This Case has been previously closed by Workbooks Support. You can re-open this ticket at any time by providing a reason why you'd like to do so and clicking "Re-open Case".
        <table class="update_case">
         <tr><td style="padding: 10px">Summary:<input id="name" name="name" type="text" size="80" maxlength="255" class="required"/></td></tr>
         <tr><td><textarea id="description" name="description" cols="255" rows="50"></textarea></td></tr>
         <tr>
          <td colspan="2" style="padding-top: 10px;">
            <input type="file" class="file" name="file1" id="file1" style="display: inline">
            <input type="file" class="file" name="file2" id="file2" style="display: inline">
            <input type="file" class="file" name="file3" id="file3" style="display: inline">
          </td></tr>
      </table>
      <p><button type="submit" onclick="on_reopen_case()" style="float:left; margin-top: 10px; margin-bottom: 10px;" value="reopen_case" id="reopen_case" name="reopen_case" class="quietbutton">Re-open Case</button></p>
    </div>
  </div>

Meine Javascript:

<script type="text/javascript">
    function on_reopen_case() {
      if (!$("#reopen_case_form").valid()){ return false; }
      $('#reopen_case').attr('disabled', 'disabled');
      $('#reopen_case').text('Re-opening case. Please wait...');
      document.body.style.cursor = "progress";
      $("#function").val("reopen_case");
      fade();
      $("#reopen_case_form").submit();
    };
  </script>

Form scheint zu senden, aber nicht ändern Sie den text der Schaltfläche zu "Re-opening case" und es nicht gesetzt #Funktion, um den angegebenen Wert entweder.

Dummerweise habe ich verwendet, ähnlich wie sonst wo und das funktioniert:

<div id="tab3" class="tab">
     <div id="update_case_form">
        Provide a summary and detailed description of your update below, including screenshots where applicable. Click "Update Case" to submit your update to the Workbooks Support team.
      <table class="update_case">
         <tr><td style="padding: 10px">Summary:<input id="name" name="name" type="text" size="80" maxlength="255" class="required"/></td></tr>
         <tr><td><textarea id="description" name="description" cols="255" rows="50"></textarea></td></tr>
         <tr>
          <td colspan="2" style="padding-top: 10px;">
            <input type="file" class="file" name="file1" id="file1" style="display: inline">
            <input type="file" class="file" name="file2" id="file2" style="display: inline">
            <input type="file" class="file" name="file3" id="file3" style="display: inline">
          </td></tr>
      </table>
      <p><button type="submit" onclick="on_create_activity()" style="float:left; margin-top: 10px; margin-bottom: 10px;" value="create_activity" id="create_activity" name="create_activity" class="quietbutton">Update Case</button></p>
     </div>
  </div>

Javascript

 <script type="text/javascript">
    function on_create_activity() {
      if (!$("#update_case_form").valid()){ return false; }
      $('#create_activity').attr('disabled', 'disabled');
      $('#create_activity').text('Updating case. Please wait...');
      document.body.style.cursor = "progress";
      $("#function").val("create_activity");
      fade();
      $("#update_case_form").submit();
    };
  </script>

Ich kann nicht herausfinden, für das Leben von mir, wohin ich gehe falsch! Hilfe....

  • Wo ist Ihre form?
  • Wie @mariocatch ist zu sagen, Sie müssen verwenden Sie die <form> element zu verwenden, die submit() Veranstaltung. Ändern Sie Ihre <div id="reopen_case_form"> zu <form.. und sehen, welche Fehler Sie erhalten dann 🙂
  • Habe gerade versucht das zu schnell und ich habe jetzt eine ähnliche Meldung: "Uncaught TypeError: Cannot read property 'form' von undefined
  • Schaffen Sie den <div id="reopen_case_form">.... in einer Schleife in php? Ist es möglich, Sie haben n Anzahl der <div id="reopen_case_form"> im gleichen html-Dokument?
  • Ich bin durch die Erstellung von Registerkarten am unteren Rand des Bildschirms, eines der tabs content-Generierung erfolgt über eine PHP-foreach-Schleife. Es funktioniert nicht über einen submit-button, wenn. Der Verweis auf reopen_case_form existiert nur einmal...
  • Blick auf eine ähnliche Frage stackoverflow.com/q/32688197/689579. Dieser Fehler kann verursacht werden, durch die un-eindeutige ids. Haben Sie sichergestellt, dass #reopen_case_form und #reopen_case sind nur einmal im gesamten html-Dokument?
  • Danke @Sean. Ich habe gerade überprüft, die id ' s und das ist der einzige Ort,...

InformationsquelleAutor Jamie Lowe | 2015-12-19
Schreibe einen Kommentar