[Django]-How to submit Django form using Javascript?

5👍

Your template does not have the <form></form> tags, without those there is no form to submit.

You should write:

<form id="MyForm">
    <div class="controls">
    ...
    <input type="submit" value="Say hello" onclick="sendEmail(this);">
    </div>
</form>

That should do it, but in case it doesn’t (I realy think it will), you can add this to your sendEmail function:

document.getElementById("myForm").submit();

-1👍

how about onclick="this.submit()"

Leave a comment