logo

Very Short Question and Answers - Buttons and TextArea


Q 1.
Which HTML tags can be used to create buttons on a web page?

Ans:

Buttons can be created using the <input> tag (with types 'submit', 'reset', or 'button') or the <button> tag.

Q 2.
What is the difference between a 'submit' button and a 'reset' button in an HTML form?

Ans:

A 'submit' button sends form data to the server, while a 'reset' button clears all form fields and restores their default values.

Q 3.
Write the HTML code to create a button that shows an alert saying 'Welcome!' when clicked.

Ans:

<button onclick="alert('Welcome!')">
Click Here
</button>
Q 4.
Explain the purpose of the 'disabled' attribute for buttons.

Ans:

The 'disabled' attribute makes the button inactive so users cannot click or interact with it.

Q 5.
Which attribute would you use in the <input> tag to specify custom text on the button?

Ans:

The 'value' attribute specifies the text displayed on the button.

Q 6.
What is the tag and key attributes used to create a multi-line text field?

Ans:

The <textarea> tag is used with attributes like 'rows', 'cols', and 'name' to create a multi-line text field.

Q 7.
Differentiate between <input type="text"> and <textarea>.

Ans:

<input type="text"> creates a single-line text field, while <textarea> allows users to enter multi-line (long) text.

Q 8.
How do you make a textarea display a hint before the user types anything?

Ans:

By using the 'placeholder' attribute within the <textarea> tag.

Q 9.
What does the 'readonly' attribute do in a <textarea>?

Ans:

It makes the textarea non-editable; users can view the content but cannot change it.

Q 10.
Write the HTML code for a textarea that is 5 rows high and 40 columns wide.

Ans:

<textarea rows="5" cols="40"></textarea>

Q 11.
Which attribute of <input> or <button> lets you trigger JavaScript when the button is clicked?

Ans:

The 'onclick' attribute triggers JavaScript code when the button is clicked.

Q 12.
Name two situations where you would use a multi-line text field (textarea) instead of a textbox.

Ans:

When collecting user feedback or when entering addresses that require more than one line.

Q 13.
Can the <button> tag hold images or only text? Explain.

Ans:

The <button> tag can hold both text and other elements like images (such as <img>).

Q 14.
What is the 'maxlength' attribute used for in a <textarea>?

Ans:

The 'maxlength' attribute limits the maximum number of characters that can be entered in the textarea.

Q 15.
If you want to collect long answers in a form, which tag will you use and why?

Ans:

I will use the <textarea> tag because it allows users to enter multiple lines of text, suitable for long answers.

Q 16.
Write the code for an input button that is named 'greetBtn', shows 'Say Hi', and does nothing when clicked.

Ans:

<input type="button" name="greetBtn" value="Say Hi">
Q 17.
Explain the use of 'rows' and 'cols' attributes in <textarea>.

Ans:

'rows' specifies the number of visible lines, and 'cols' specifies the width (number of characters per line) of the textarea.

Q 18.
How does the 'reset' button affect a <textarea> inside a form?

Ans:

Clicking the 'reset' button will clear the contents of the <textarea> and restore its default value.

Q 19.
Which tag and attributes would you use to create a non-editable multi-line message displayed in a form?

Ans:

Use

<textarea rows="x" cols="y" readonly>Message</textarea>

to create a non-editable, multi-line message.

Q 20.
List any three common attributes shared by both <input type="button"> and <button> tags.

Ans:

Common attributes are: 'type', 'disabled', and 'onclick'.