It should fill the field but it does nothing, why?
<html>
<input type="button" id="phoneButton">
<input type="text" id="allQuery">
<script>
// catch CLICKING with mouse to fill the text field
var input = document.getElementById('phoneButton')
input.addEventListener('click', function(e)
{
document.getElementById('allQuery').value = 'hello'
}, false)
</script>
</html>
[Update]
…my point was not really the typo, I have more code like this but much longer and for some reason such addEventListeners do not notice the objects with which they are used with (such as the phonebutton). What is the problem with longer code? How to make sure the eventListeners have loaded vars so that they do not get cleared from the cache with long code?
getElementByIdis a method ofdocument, not global function.Also make sure the
#phonebuttonelement exists when Javascript runs;DOMContentLoadedevent is often helpful.