They possibly are the most used element in Html forms.The text fields allow us to request information from our users, which they can fill in by theirselves.The tag we will be using for this one is:
<input type="text" name="text" id="text" value=""/>
You may surely be wondering about the attributes name, id and value.I will give you a brief explanation:
name:This will be the name that we are giving our text field, it doesn't appear in the text field.
id:This is used in javascript.It gives the field a unique value on the whole website.
value:What you type between the quotes will appear in the text field, if you don't type anything, the field will appear empty.
There are also some more attributes you can add to Html text fields that are not obligatory:
disabled:As the name says by itself, the field is disabled.The user can't type any information in it.It is very used by websites that want you to fill in their fields one by one, so if you haven't filled in a field, the next one will be disabled.
maxlength:Gives the user a limit of characters to type in.
size:Defines the length of the text field in pixels.
Example of a form with all of the previous attributes:
<head></head>
<body>
<form>
<input type="text" name="Name" id="text" value="Name" /><br/><br/>
<input type="text" name="disabled" id="disabled" value="Disabled" disabled/><br/><br/>
<input type="text" name="maxlength" id="maxlength" value="8 characters max." maxlength="8"/><br/><br/>
<input type="text" name="size" id="size" value="This field has a length of 100" size="100"/>
</form>
</body>
</html>
No comments:
Post a Comment