Answer:
A textbox lets users enter any single line of text such as a name or city. Example:
<input type="text" name="username" />
A checkbox allows users to select multiple options from a group, like hobbies. Each checkbox works independently, so you can tick more than one. Example:
<input type="checkbox" name="hobby" value="music" /> Music
A radio button forces the user to choose only one among options in a group (like gender). All radio buttons in the group share the same name. Example:
<input type="radio" name="gender" value="male" /> Male
So, textbox = any text, checkbox = many options, radio button = just one choice.
name, value, and checked attributes in input elements. Give HTML examples.Answer:
The name attribute groups input fields so their data can be sent to the server. For example,
<input type="radio" name="gender" value="male" />
groups radio buttons as "gender".
The value attribute sets what is submitted if that control is picked or filled. For checkboxes and radio buttons, it shows what data goes if checked (e.g., value="reading" for hobbies).
The checked attribute pre-selects or ticks a default option:
<input type="checkbox" checked />
These attributes control the behavior, grouping, and default selections in forms, making data collection clear.
Answer:
To limit length in a textbox, use the maxlength attribute. For example:
<input type="text" maxlength="5" />
This means users can type only up to 5 characters—extra ones are ignored.
It is helpful for fields like PIN codes or short names, preventing long or incorrect entries.
This ensures data fits expected length and improves data accuracy.
It also guides users to type only what is necessary and stops mistakes before the form is submitted.
placeholder attribute? Why is it important in designing forms?Answer:
The placeholder attribute shows a hint or example text inside the textbox or password field before the user types.
Example:
<input type="text" placeholder="Enter your name" />
It tells the user what kind of data to enter—like giving an instruction inside the box itself.
It disappears as soon as typing begins.
This improves user experience by reducing confusion and making forms more self-explanatory.
Placeholder text also prevents mistakes, saves time, and can reduce help requests because the form is easier to understand.
name attribute? What happens if they don’t?Answer:
All radio buttons in a group must have the same name attribute so the browser knows they belong together.
This ensures only one radio button can be selected at a time.
If different names are given, each button is treated as separate, and the user could select multiple options, which defeats the purpose of a "single-choice" question.
For example, in a gender selection:
<input type="radio" name="gender" ... />
for all choices ensures exclusivity.
This rule guarantees the form captures only one answer for that question, keeping form data correct.
Answer:
HTML code:
<form>
Name: <input type="text" name="studentname" placeholder="Enter name" /><br />
Gender:<br />
<input type="radio" name="gender" value="male" /> Male<br />
<input type="radio" name="gender" value="female" /> Female<br />
Hobbies:<br />
<input type="checkbox" name="hobby" value="reading" /> Reading<br />
<input type="checkbox" name="hobby" value="sports" /> Sports<br />
</form>
Here, the textbox receives the student's name.
Radio buttons (with the same name) offer male or female, but only one can be chosen.
Checkboxes allow students to select both or either hobby—they are independent.
Each control collects different types of data, making the form complete and useful for records.
Answer:
A password input type (<input type="password">) functions like a textbox, but the characters entered are hidden (as stars or dots).
This prevents people nearby from seeing the password as you type, protecting confidential information.
A normal textbox shows all entered text clearly.
By hiding input, password fields make online registrations and logins safer and private.
It reduces the risk of password theft or misuse, especially in public places or on shared computers.
Using the password field is a basic rule for security on any website.
name attribute, what problem can occur during form submission? Why is name essential?Answer:
The name attribute is what the browser uses to send data to the server.
If an input (like <input type="text">) has no name, that field's value will not be sent at all when the user submits the form.
This means important data could be lost, making the form incomplete or useless for its purpose.
For example, a user may type their email, but if there's no name (<input type="text" name="email">), the server won't receive it.
Consistent use of name makes sure every piece of collected user input is sent, stored, or processed as needed.
Thus, it's a key part of form data collection.
Answer:
To pre-select “Reading” in a list of checkboxes, add the checked attribute:
<input type="checkbox" name="hobby" value="reading" checked /> Reading
This means when the form loads, Reading is already ticked.
It's helpful when a common or recommended choice should be suggested to users, or to show default selections in surveys.
It improves form
placeholder and maxlength attributes together in a textbox, especially for fields like PIN codes or phone numbers? Provide a real-world example.Answer:
Using placeholder gives a hint of what to enter (like "Enter 6-digit PIN") so the user knows the expected data.
maxlength limits input to a maximum number (like 6 for a PIN or 10 for a phone number), stopping errors before they happen.
Together, they guide and restrict the user, preventing too-short or too-long entries.
Example:
<input type="text" placeholder="Enter 6-digit PIN" maxlength="6" />
This approach makes the form user-friendly, reduces mistakes, and ensures only valid data is entered.
It also saves time for both users and those processing the forms by ensuring accurate input.