HTML Forms- How to create HTML Forms with codes

 

  1. Choose the correct answer:-

  1. Which of the following HTML form control is not created using <INPUT> tag?

Ans- d-select list

  1. Which of the following controls can be set to one of the two positions only?

Ans-  C – Both a and b

  1. In a list of cities, the city Mumbai was already selected in an HTML form. This is due to _________

Ans:- b-selected attribute

  1. Mukul is creating an HTML based MCQs quiz with questions where multiple answers could be true. Which of the following code must be most suitable and easy for him to use?

Ans- a- <input type=checkbox>

  1. Select the odd one out?

Ans- b- type=radio

2. Fill in the blanks Ans: .

  1. ID
  2. Textbox
  3. Reset
  4. TextArea
  5. Select, option

Answer the following questions:-

  1. What is the use of HTML Forms?

Ans:- There are following uses of HTML forms-

  • Collecting data from users
  • It enables creating account and login forms
  • It is created for online surveys, polls
  • HTML forms are created to sell or purchase products

And there are many more use cases of HTML forms.

  1. Write HTML form code to accept username and password from the user.

Ans:

<html>

<head>

<title>Login Form</title>

</head>

<body>

<h2>Login</h2>

<form action=”/submit-form” method=”post”>

<label for=”username”>Username:</label><br>

<input type=”text”><br>

<label for=”password”>Password:</label><br>

<input type=”password”><br>

<input type=”submit” value=”Login”>

</form>

</body>

</html>

  1. How are radio buttons grouped in HTML form. Explain with an examples?

Ans:-

Radio buttons are grouped using the name attribute.

. When multiple radio buttons share the same name, only one option can be selected at a time from that group. For example: Choosing a Favorite Fruit

<form>

  <h3>Select your favorite fruit:</h3>

<input type=”radio” name=”fruit” value=”apple”>

  <label for=”apple”>Apple</label><br>

  <input type=”radio” name=”fruit” value=”banana”>

  <label for=”banana”>Banana</label><br>

  <input type=”radio” id=”cherry” name=”fruit” value=”cherry”>

  <label for=”cherry”>Cherry</label><br>

  <input type=”submit” value=”Submit”>

</form>

  1. What do reset and submit types of buttons do in an HTML form?

Ans- In an HTML form, the buttons with type=”submit” and type=”reset” serve two very different but essential functions.

Submit

Sends the form data to a specified server or endpoint.

– Usually triggers action defined in the form’s action attribute.

<input type=”submit” value=”Send Form”>

Reset

Clears all input fields in the form.

– Restores default values (if any were provided in the HTML).

<input type=”reset” value=”Clear Form”>

 

  1. What is the significance of attributes multiple and selected?

Ans- To allow the users to select multiple items in the list, specify multiple in the <select> tag.

<SELECT name=”fruits-type” multiple>

Selected attribute can be specified with <OPTION> tag to show an item already selected when the list is displayed.

<OPTION value=”Apple” selected>Apple</OPTION>

Also Read:

AI and Data

 

Leave a Comment

Your email address will not be published. Required fields are marked *