The HTML <input type="submit"> element is used to create a submit button in a form. It sends the form data to the server when clicked.
- Used to submit form data to the server.
- Created using <input type="submit"> inside a <form> element.
- Supports attributes like value, disabled, and formaction.
Syntax:
<input type="submit"> Attributes
- value: Specifies the text displayed on the submit button.
- name: Defines a name for the submit button used in form data.
- disabled: disabled disables the submit button and prevents form submission.
- form: Specifies the form associated with the submit button.
- formaction: formaction defines the URL where form data is sent for processing.
- formenctype: formenctype specifies how form data should be encoded before submission.
- formmethod: formmethod specifies the HTTP method (GET or POST) used for form submission.
- formtarget: formtarget specifies where to display the response after form submission.
- autofocus: autofocus automatically focuses the submit button when the page loads.
- formnovalidate: formnovalidate prevents form validation during form submission.
Note: The form handler is defined in the action attribute of the form.
Example: We are using the HTML <input type="submit"> to create a submit button for a form. When clicked, it submits the form data (username and password) to the server for processing.
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<body style="text-align:center;">
<h2>HTML <input type="submit"></h2>
<!--Driver Code Ends-->
<form action="#">
<label for="uname">User Name:</label>
<input type="text" id="uname">
<br><br>
<label for="pwd">Password:</label>
<input type="password" id="pwd">
<br><br>
<input type="submit" value="Submit">
</form>
<!--Driver Code Starts-->
</body>
</html>
<!--Driver Code Ends-->