Skip to content Skip to sidebar Skip to footer

JS - How To Submit Form Onclick And Send Submit Button

I need to submit form by button which is out of scope of the form by JavaSript.
Copy

if you have multiple forms in the document then set id to the form

<form id="form1">
  <input name="data" type="text">
  <input type="submit" name="send" id="send-button" style="display: none">
</form>
<button onclick="document.getElementById("form1").submit()"></button>

Solution 2:

Give the form a name:

    <form name="myform">
        <a href="javascript: submitform()">Submit</a>
    </form>

Submit form function:

    <script type="text/javascript">
        function submitform()
        {
           document.myform.submit();
        }
    </script>

Invoke submission:

    document.forms["myform"].submit();

Solution 3:

you should add value attribute on submit button like that

<input type="submit" name="send" value="xyz" id="send-button" style="display: none">

i think you will received both values


Post a Comment for "JS - How To Submit Form Onclick And Send Submit Button"