A small Javascript function to capitalize the contents of a text fields is as follows:
<html>
<head>
<title>capitalize</title>
</head>
<body>
<input type="text" id="uname" length="20" /><br />
<input type="submit" id="submit" value="submit" />
<script>
document.getElementById("submit").addEventListener("click",eve);
function eve(){
var uname = document.getElementById("uname").value;
uname = uname.toUpperCase();
document.getElementById("uname").value=uname;
}
</script>
</body>
</html>
Now, this is working normally, but when I change the location of the Javascript code to head tag, it's not working.
<html>
<head>
<title>key events</title>
<script>
document.getElementById("submit").addEventListener("click",eve);
function eve(){
var uname = document.getElementById("uname").value;
uname = uname.toUpperCase();
document.getElementById("uname").value=uname;
}
</script>
</head>
<body>
<input type="text" id="uname" length="20" /><br />
<input type="submit" id="submit" value="submit" />
</body>
</html>