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 85 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
Our brains are wired to find things we are looking for - if your always cynical or waiting for things to go wrong, then your life will reflect that. On the other hand, having a positive outlook on life will bring you joy and provide you with inspiration when you least expect it ☀ïļðŸ‰ðŸŒī
Unknown