submit a form with javascript onclick

submit a form with javascript, good if you want to submit a form with a button that is not within that form.

the form will require an id

HTML

<form id='theform'>
	<input type='text'>
</form>

<p>usually this would not work with a button outside the form element</p>
<div>
	<button onclick='document.getElementById("theform").submit();' class='btn btn-primary'>Submit the above form</button>
</div>

Javascript

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

usually this would not work with a button outside the form element

Other Items in javascript

No Items Found.

Add Comment
Type in a Nick Name here
 
Page Views

This page has been viewed 83 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹

Random Quote
1. Show your work to the world instead of keeping in your head💆. 2. Do the work consistently👌 3. Respect your work🥰 4. Don't postpone your work 5. Make mistakes 🔥🔥🔥
Unknown