My question is: how can I combine the "placeholder text" Javascript Functions that I have inserted in to the "head" section in to one Javascript Function, so that only one Function can execute the "placeholder text" Javascript code on all the different "input fields" that I would like to create, to make my Javascript code look more simpler and neat? Thanks guys!
Example, one Javascript Function that will execute all the different placeholder text for:
- A placeholder text for First Name
- A placeholder text for Last Name
- A placeholder text for Email
- A placeholder text for password
etc, etc...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Javascript Practice</title>
<script type="text/javascript">
//For the first input field: "First Name"
function fnameBlur(x)
{
document.getElementById(x).value='First Name';
}
function fnameFocus(x)
{
document.getElementById(x).value='';
}
//For the second input field: "Last Name"
function lnameBlur(x)
{
document.getElementById(x).value='Last Name';
}
function lnameFocus(x)
{
document.getElementById(x).value='';
}
</script>
</head>
<body>
First name: <input type="text" onblur="fnameBlur(this.id)" onfocus="fnameFocus(this.id)" id="fname" value="First Name" />
Last name: <input type="text" onblur="lnameBlur(this.id)" onfocus="lnameFocus(this.id)" id="lname" value="Last Name" />
</body>
</html>