简体   繁体   中英

Uncaught TypeError: Cannot read property 'element' of undefined when submitting form

I have an HTML div output using PHP which when "Submit" is clicked, it should submit the form and fire a JS function. When submitted, the JS console in Chrome gives me the following error:

Uncaught TypeError: Cannot read property 'element' of undefined

My HTML (wrapped in a 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>

My 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>

The form appears to submit but doesn't change the the button text to "Re-opening case" and it doesn't set #function to the specified value either.

Annoyingly I've used similar else where and this works:

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

I can't figure this out for the life of me where I'm going wrong! Help....

I think I may have figured this out... I was using nested forms which is apparently not allowed... Cannot Read Property 'Elements' of Undefined - in JS Console

Thanks for the suggestions guys :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM