Form Attributes


Form Attributes

  • Action

    When a form is submitted, the action to be performed is decided by this attribute. The form data submitted goes to a file on a server after clicking on the submit button. If the attribute is not specified, the action is set to the current webpage.

  • Target

    The response to be displayed after submitting the form is decided by this attribute. The attribute can have one of the following values: _blank, _self, _parent, _top, or framename.

  • Method

    When form data is submitted, the HTTP method can be specified. It can have either get or post value. The default is the get. The post method can be used if the form contains sensitive or personal information.

  • Autocomplete

    This attribute can be used to specify whether a form should have autocomplete on or off. The browser automatically completes values based on values that the user has entered before if autocomplete is on.

  • Novalidate

    This attribute is a boolean attribute. If this attribute is present it means the form data should not be validated while submitting.

  • Example No.1:

    <html> <body> <h2>Knowledge2life</h2> <form> <label for="fname">First name:</label><br> <input type="text" id="fname" name="fname" value="Knowlegde2"><br> <label for="lname">Last name:</label><br> <input type="text" id="lname" name="lname" value="Life"><br><br> <input type="submit" value="Submit"> </form> </body> </html>

    OUTPUT:

    Knowledge2life






    Example No.2:

    <html> <body> <h2>Knowledge2life</h2> <form action="/action_page.php" target="_blank"> <label for="fname">First name:</label><br> <input type="text" id="fname" name="fname" value="John"><br> <label for="lname">Last name:</label><br> <input type="text" id="lname" name="lname" value="Doe"><br><br> <input type="submit" value="Submit"> </form> </body> </html>

    OUTPUT:

    Knowledge2life