I'm trying to define a variable as the text a user enters into a form by the getElementById method. And then display that information in an alert box. But I'm not having any luck. Below is the code I've got. I have it working with
var a = document.form_one.abc.value;
but I'm thinking that getElementById is a more updated way.
Help!
<html>
<head>
<title>get element by id test</title>
</head>
<body>
<script type="text/javascript">
function g_test()
{
var a = document.getElementById('M_one');
alert(a);
}
</script>
<form name="form_one">
<input type="text" name="abc" id="M_one">
<input type="button" value="Click to test" onClick= "g_test()">
</form>
</body>
</html>