I want to get all input element in html page. I've tried this:
window.onload = function(){
input = document.querySelectorAll("input");
}
But, when I check it with alert function outside onload, it doesn't do anything
alert(input.length) // doesn't do anything
If I use this, this will give me the numbers of input element in html page.
window.onload = function(){
input = document.querySelectorAll("input");
alert(input.length);
}
And that's mean I can't access it outside. How can I access it outside?
UPDATE
This is how the html page looks like:
<html>
<head>
<script type="text/javascript" src="actions.js"></script>
</head>
<body>
<label for="name">Name:</label><br/>
<input type="text" id="name" /><br/>
<label for="address">Address:</label><br/>
<input type="text" id="address" /><br/>
<label for="email">E-mail:</label><br/>
<input type="text" id="email" />
</body>
</html>
var, so you can access it outside the function. You'll have to post more code in order for anybody to tell what's going wrong. (Ifalert(input.length)really does not do anything then there's an error and you should check your developer console.)onload? You may simply be checking too early, beforeonloadhas actually been called.alert(input.length)right belowonloadfunction (in first example). So, thealertfunction is called first?