HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

HTML Form Attributes

HTML form elements can have several attributes that define their behavior, appearance, and interactions. Here are some common attributes used with HTML form elements:


Action Attribute:

Specifies the URL to which the form data will be sent when the form is submitted.

Example

<form action="/submit" method="post">
            
You can click on above box to edit the code and run again.

Output


Method Attribute:

Specifies the HTTP method used when sending form data to the server. Common values are "get" and "post."

Example

<form action="/submit" method="post">
            
You can click on above box to edit the code and run again.

Output


Target Attribute:

Specifies the target window or frame where the form response should be displayed.

Example

<form action="/submit" method="post" target="_blank">
            
You can click on above box to edit the code and run again.

Output


Name Attribute:

Specifies a name for the form. This is used to identify the form when working with JavaScript or in server-side processing.

Example

<form name="myForm" action="/submit" method="post">
            
You can click on above box to edit the code and run again.

Output


Enctype Attribute:

Specifies the encoding type used to submit the form data to the server when the method is "post." Common values include "application/x-www-form-urlencoded" and "multipart/form-data."

Example

<form action="/submit" method="post" enctype="multipart/form-data">
            
You can click on above box to edit the code and run again.

Output


Accept-charset:

Specifies the character encodings that are acceptable for the form submission.

Example

<form action="/submit" method="post" accept-charset="UTF-8">
            
You can click on above box to edit the code and run again.

Output


Autocomplete:

Controls whether the browser should automatically complete the form fields based on the user's previous input.

Values: "on" (default) or "off."

Example

<form action="/submit" method="post" autocomplete="off">
            
You can click on above box to edit the code and run again.

Output

Target:

Specifies where to display the response after submitting the form. Common values include "_self," "_blank," "_parent," and "_top."

Example

<form action="/submit" method="post" target="_blank">
            
You can click on above box to edit the code and run again.

Output

Onsubmit:

Specifies a JavaScript function to be executed when the form is submitted.

Example

<form action="/submit" method="post" onsubmit="return validateForm()">
            
You can click on above box to edit the code and run again.

Output

Onreset:

Specifies a JavaScript function to be executed when the form is reset.

Example

<form action="/submit" method="post" onreset="resetForm()">
            
You can click on above box to edit the code and run again.

Output