Form_Submission_Methods
Form_Submission_Methods
In HTML, a form can be submitted using different methods. The 'method' attribute of the <form>
element specifies how the form data will be sent to the server. There are primarily two methods used
to submit a form:
1. GET Method:
- Example:
</form>
2. POST Method:
- Sends form data in the body of the HTTP request, not visible in the URL.
- Example:
username=John&password=secret
- Example:
<form id="myForm">
</form>
<script>
document.getElementById("myForm").onsubmit = function(event) {
event.preventDefault();
xhr.onload = function() {
} else {
};
xhr.send(formData);
};
</script>
- You can also submit a form programmatically using JavaScript by invoking the submit() method
- Example:
</form>
<script>
function submitForm() {
document.getElementById("myForm").submit();
</script>