Reputation: 5
I am working on an assignment and am a little lost. The question states:
Create a label element with the text Username. Within the label element, insert an input box for the username field. Make the field required and add the title Supply your username
Here is what I have. I am mainly confused on the title portion. Any help is greatly appreciated, and feel free to correct me on the other parts. Thank you
<form id="survey" name="survey"
action="www.sblogger/cgi-bin/subcomments"
method="post">
<fieldset id="commentFS"
<label>
Username
<input id="username">
required="required"
</label>
</fieldset>
</form>
Upvotes: 1
Views: 21826
Reputation: 201568
The assignment is not well-defined, since it does not say what kind of a title should be included. It may refer to an advisory title that may be presented to user in some situations (e.g., on mouseover), as assumed in @Jeffrey’s answer. It may also refer to text that appears inside the input box when it is empty, in which case you would use the placeholder
attribute. It can also refer to visible text before the input box; this would be the most reasonable setup. Even then, there are several alternatives. It could be just text before the label and the input box, or it could be wrapped in a heading element, or even a legend for a fieldset. The following example is based on the wild assumption that such a legend is desired (which might be a wrong guess if you have actually been told to use the fieldset
element, as you are using, although there is no reason to use it in a simple case like this).
<form id="survey" name="survey"
action="http://www.example.com/cgi-bin/subcomments"
method="post">
<fieldset id="commentFS">
<legend>Supply your username</legend>
<label>
Username
<input id="username" name="username"
required="required">
</label>
</fieldset>
<input type="submit" value="Submit">
</form>
Notes: The attribute required="required"
(or just required
unless you have been told to use XHTML syntax) must appear inside the <input ...>
element, not after it. And the input
element needs a name
attribute, otherwise the data in it will not be sent at all to the server.
Upvotes: 0
Reputation: 76240
You just need to add a title
attribute on the input
field. Also the label
tag can stay on it's own, which leaves to:
<form id="survey"
name="survey"
action="www.sblogger/cgi-bin/subcomments"
method="post">
<fieldset id="commentFS">
<label>Username</label>
<input id="username"
title="Supply your username"
required>
</fieldset>
</form>
Upvotes: 1