<html>
<body>
<input type="text" name="test" id="test" value="my text">
<input type="button" id="mybutton" value="click me">
<script>
var input = document.querySelector('input');
document.getElementById('mybutton').onclick = function ()
{
alert(input.value);
};
</script>
</body>
<html>