This code is not working:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script>
document.getElementByID("button").addEventListener('click', outInfo, false);
function outInfo () {
var user = document.getElementById("userName").value;
alert(user);
}
</script>
</head>
<body>
<p>User Name:
<input id="userName" type="text"/>
<input id="button" type="button" value="Click Me" />
</p>
</body>
</html>
This code is working:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script>
<script>
function output() {
var i = document.getElementById("input");
window.alert(i.value);
}
</script>
</head>
<body>
<p>User Name:
<input type="text" name="username" id="input" size="30"/>
<input type="button" id="button" value="Start" onclick="output()" />
</p>
</body>
</html>
What's wrong with the first one? I suppose the problem is with a function "outInfo". Which way is the best to solve such problems?
bodytag.</body>