Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
30
rated 0 times [  35] [ 5]  / answers: 1 / hits: 155925  / 11 Years ago, sat, january 11, 2014, 12:00:00

I need the button with the ID of clickButton to be automatically clicked or activated just by someone loading the page:



<html>
<head>
</head>
<body>
<center>
<form method=post action=http://web.com/>
<input type='hidden' value=test id=chatbox name='content' />

<!-- The Button -->
<input id=submitButton class=button name=accept type=submit value=Send/>

</form>
</center>
</body>
</html>


What I have tried:



<html>
<head>
<script type=text/javascript>

//In here I would use several Javascript codes,
//including all the ones I have been given
//here

</script>


</head>
<body>
<center>
<form method=post action=http://web.com/>
<input type='hidden' value=test id=chatbox name='content' />

<!-- The Button -->
<input id=submitButton class=button name=accept type=submit value=Send/>

</form>
</center>
</body>
</html>


Also if I wanted a javascript code to repeat it self, what command would I use?



Thank you for your help in advance.


More From » html

 Answers
4

I see what you really want to auto submit the form. This would do it:



window.onload = function(){
var button = document.getElementById('clickButton');
button.form.submit();
}


EDIT
If what you want is really auto submit the form automatically n times, each second, whis would do:



window.onload = function(){
var button = document.getElementById('clickButton'),
form = button.form;

form.addEventListener('submit', function(){
return false;
})

var times = 100; //Here put the number of times you want to auto submit
(function submit(){
if(times == 0) return;
form.submit();
times--;
setTimeout(submit, 1000); //Each second
})();
}


Cheers


[#73237] Friday, January 10, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ira

Total Points: 298
Total Questions: 112
Total Answers: 103

Location: Guadeloupe
Member since Sat, Aug 22, 2020
4 Years ago
;