How can I submit a form using JavaScript?

0 votes

I have a form with id theForm which has the following div with a submit button inside:

<div id="placeOrder"
     style="text-align: right; width: 100%; background-color: white;">
    <button type="submit"
            class='input_submit'
            style="margin-right: 15px;"
            onClick="placeOrder()">Place Order
    </button>
</div>

When clicked, the function placeOrder() is called. The function changes the innerHTML of the above div to be "processing ..." (so the submit button is now gone).

The above code works, but now the problem is that I can't get the form to submit! I've tried putting this in the placeOrder() function:

document.theForm.submit();

But that doesn't work.

How can I get the form to submit?

Oct 9 in Java-Script by kartik
• 35,820 points
35 views

1 answer to this question.

0 votes

Hello @kartik,

Set the name attribute of your form to "theForm" and your code will work.

Or use:

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

Also, you can use it in a function as below:

function formSubmit()
{
    document.getElementById("form1").submit();
}

Hope it helps!!
Thank you!!

answered Oct 9 by Niroj
• 78,120 points

Related Questions In Java-Script

0 votes
1 answer

How do I post a form in laravel 5 using ajax?

Hello @kartik, You can solve this error by ...READ MORE

answered Jun 11 in Java-Script by Niroj
• 78,120 points
144 views
0 votes
1 answer

How can I display a JavaScript object?

Hello @kartik, Use native JSON.stringify method. Works with nested objects ...READ MORE

answered Aug 28 in Java-Script by Niroj
• 78,120 points
46 views
0 votes
1 answer

How can I check whether a radio button is selected with JavaScript?

Hello @kartik, You can use vanilla JavaScript way var radios ...READ MORE

answered Sep 3 in Java-Script by Niroj
• 78,120 points
76 views
+1 vote
1 answer

How can we send message multiple time to a specific person or group in whatsapp using loop?

Hii @kartik,  This is simple task to send single ...READ MORE

answered Feb 28 in Java-Script by Niroj
• 78,120 points
764 views
0 votes
1 answer

jQuery AJAX fires error callback on window unload - how do I filter out unload and only catch real errors?

Hello, In the error callback or $.ajax you have three ...READ MORE

answered Apr 27 in Java-Script by Niroj
• 78,120 points
448 views
0 votes
1 answer

How do I pass command line arguments to a Node.js program?

Hello @kartik, If your script is called myScript.js ...READ MORE

answered May 5 in Java-Script by Niroj
• 78,120 points
697 views
0 votes
1 answer

Error:Issue when trying to use IN() in wordpress database

Hello @kartik, Try this code : // Create an ...READ MORE

answered May 8 in PHP by Niroj
• 78,120 points
91 views
+2 votes
1 answer

How do I debug Node.js applications?

Hello @kartik, Use node-inspector  from any browser supporting WebSocket. Breakpoints, ...READ MORE

answered Jul 8 in Node-js by Niroj
• 78,120 points
87 views
0 votes
2 answers

How can I set a session var using javascript and get it via php code?

Yes it is possible. You can either ...READ MORE

answered Aug 9 in Java-Script by Okugbe
• 280 points
3,107 views
0 votes
2 answers

How can I set focus on an element in an HTML form using JavaScript?

Hi Kartik, try the following script <script>  (window.onload = ...READ MORE

answered Sep 24 in Java-Script by Okugbe
• 280 points
65 views