Reputation: 27
I need a script that will click a button on page load but I can't get it to work. I can throw the javascript line into firebug and it works fine...
<script type="text/javascript">
document.getElementById("evcal_next").click();
</script>
in the head section of the page... what am i doing wrong?
Upvotes: 0
Views: 33
Reputation: 382132
The problem is that you execute this when there isn't an element with id evcal_next
. You can either :
The second solution would be like this :
<script>
window.addEventListener('load', function(){
document.getElementById("evcal_next").click();
});
</script>
EDIT
To "click evcal_next
then pause for a few miliseconds, then click evcal_prev
", you can do this :
<script>
window.addEventListener('load', function(){
document.getElementById("evcal_next").click();
setTimeout(function(){
document.getElementById("evcal_prev").click();
}, 2000); // 2 seconds
});
</script>
Upvotes: 1