Customising the input text HTML tag
Input "text" is an object to enter a single line of text whose content will be part of form data.
<form name="formname" action="" method="POST">
<input type="text" name="textname" id="textid" value="" />
</form>
You can access the attributes of the object by the id or the chain of names like this:
document.formname.textname
Input password and textarea objects are similar to input text.
Input tags for specialized types of data
Password
It is equivalent to the text object with the difference that the text assigned to the value attribute is hidden, and replaced by asterisks.
<input type="password" value="">
Its use and operations are the same.
Textarea
It works like text, but displays several lines. The content is enclosed between a opening a a ending tags.
Attributes:
- cols
Number of characters per line. The width in pixels is the average font width. Replaces the size attribute. - row
Number of visible lines.
Example:
<textarea rows="5" cols="40">
Initial content.
</textarea>
You can use textarea as text to add static data to a form, with the readonly attribute.
How to customize the input text tag
We use event handlers to take account of user actions and CSS to improve the appearance of the graphic object. Example:
The HTML Code:
<form name="formname" method="post" action="">
<input name="textname" class="textfield" type="text" size="40" maxlength="60"
value="Enter a text"
onChange="change(this)"
onFocus="getfocus(this)"
onBlur="losefocus(this)" >
<input type="button" value="Clear" onClick="cleartext()">
</form>
The CSS code:
.textfield
{
font-family:"Segoe Print", Verdan, Arial;
-moz-border-radius:4px;
border:1px solid gray;
border-radius:4px;
background-image:url(images/paper.jpg);
padding-left:8px;
}
The JavaScript code:
function cleartext()
{
document.formname.nomtexte.value="";
}
function change(element)
{
var storage = document.getElementById("storage");
storage.innerHTML += element.name + " change<br>";
}
function getfocus(element)
{
var storage = document.getElementById("storage");
storage.innerHTML += element.name + " on focus<br>";
}
function losefocus(element)
{
var storage = document.getElementById("storage");
storage.innerHTML += element.name + " loses focus<br>";
}
See also