Can’t submit a form dynamically via JavaScript in WordPress

I’m working on the backend settings of a WordPress plugin and thought I’d build a simple table enable editing of the data in the Custom Options menu of the plugin.

In case you are looking at the screenshot and wondering, it is a data on the anniversaries of loved ones who have passed away in previous years, known in Church as “the Year’s Mind”. Nothing sinister, I assure you!

The PHP is

$html .= "<form name='updateRow_". $post->ID ." method='post' action='includes/yearsmind-update.php'>";
              $html .= "<input type='hidden' name='ID' value='" . $post->ID . "'>";
              $html .= "<input type='hidden' name='firstName' value='" . $post->firstName . "'>";
              $html .= "<input type='hidden' name='middleName' value='" . $post->middleName . "'>";
              $html .= "<input type='hidden' name='lastName' value='" . $post->lastName . "'>";
              $html .= "<input type='hidden' name='fullDate' value='" . $post->fullDate . "'></form>";

The button is:

<button type='button' onclick='document.updateRow_".$post->ID.".submit()')>Update</button>

The $html string is written out nicely to the backend, and when I click on the update button, I can pick up the javascript function and display the passed $post->ID

Backend output as desired

However, I cannot seem to programmatically submit the specified form. The submit method throws an error:

Uncaught TypeError: Cannot read properties of undefined (reading 'submit')

I have tried just passing a reference to the form via Form ID which gets through to a JavaScript function and displays passed reference, fine, but as the button can only be clicked after the form has fully loaded, it seems that none of the document.addEventListener('DOMContentLoaded', () => { events make any difference.

I have tried to simplify it by programming in the submit code into the form, and still it is throwing up an error!

Once the form is submitted to a PHP file, I plan to construct the UPDATE sql and execute it, but I’d just like to get the data POSTed first!

I bet the solution is obvious, but I can’t work out the solution without your generous help… Thank you.