How to simulate click on Submit button?

E

Eli

HI! I made some quiz using one HTML form (few question with few
radio-button each like potential answers) that have one Submit button.
I would like to simulate click on this button (e.g. named "Finish")
after some time, 10 minute or so, which be equal like click on submit
button and terminate quiz (open another page or so). I tried to solve
it by JavaScript but won't, always error, like can't detect button like
object. What to do? Listing is:

<script type="text/javaScript">
var t=setTimeout("alert('Time of 60 sec is up!')",60000)
document.forms[0].submit();
document.getElementByTagName("Finish").click();
//Also I tried this:
//document.getElementById("Finish").click();
//but doesn't working! :(
document.getElementById("quizform").submit();
</script>

<p>&nbsp;</p>
<form action="results.php" method="post" name="quizform"
target="_blank" id="quizform">
....
....
<input name="Finish" type="submit" id="Finish" value="Finish" />
</form>
<p>&nbsp;</p>
</body>
</html>
 
L

Lee

Eli said:
HI! I made some quiz using one HTML form (few question with few
radio-button each like potential answers) that have one Submit button.
I would like to simulate click on this button (e.g. named "Finish")
after some time, 10 minute or so, which be equal like click on submit
button and terminate quiz (open another page or so). I tried to solve
it by JavaScript but won't, always error, like can't detect button like
object. What to do? Listing is:

<script type="text/javaScript">
var t=setTimeout("alert('Time of 60 sec is up!')",60000)
document.forms[0].submit();
document.getElementByTagName("Finish").click();
//Also I tried this:
//document.getElementById("Finish").click();
//but doesn't working! :(
document.getElementById("quizform").submit();
</script>

You don't seem to understand how setTimeout() works.
Your script will delay one minute and then popup the alert().
The rest of your script is executed immediately, before the
form exists, which causes the error.

<script type="text/javascript">
setTimeout"alert('Time is up');document.forms[0].submit()",60000);
</script>


--
 
R

Randy Webb

Eli said the following on 8/22/2006 4:16 PM:
HI! I made some quiz using one HTML form (few question with few
radio-button each like potential answers) that have one Submit button.
I would like to simulate click on this button (e.g. named "Finish")
after some time, 10 minute or so, which be equal like click on submit
button and terminate quiz (open another page or so). I tried to solve
it by JavaScript but won't, always error, like can't detect button like
object. What to do? Listing is:

<script type="text/javaScript">
var t=setTimeout("alert('Time of 60 sec is up!')",60000)
document.forms[0].submit();
document.getElementByTagName("Finish").click();
//Also I tried this:
//document.getElementById("Finish").click();
//but doesn't working! :(
document.getElementById("quizform").submit();
</script>

<p>&nbsp;</p>
<form action="results.php" method="post" name="quizform"
target="_blank" id="quizform">
....
....
<input name="Finish" type="submit" id="Finish" value="Finish" />
</form>
<p>&nbsp;</p>
</body>
</html>

var t=setTimeout(someFunction,60000)
function someFunction(){
alert('Your 60 seconds are up');
document.quizform.submit();
}
 
O

ozfred

Eli said:
HI! I made some quiz using one HTML form (few question with few
radio-button each like potential answers) that have one Submit button.
I would like to simulate click on this button (e.g. named "Finish")
after some time, 10 minute or so, which be equal like click on submit
button and terminate quiz (open another page or so). I tried to solve
it by JavaScript but won't, always error, like can't detect button like
object. What to do? Listing is:

<script type="text/javaScript">
var t=setTimeout("alert('Time of 60 sec is up!')",60000)

setTimeout is not a pause button, the above line will not stop
execution of the rest of the script.

document.forms[0].submit();

This line will be executed immediately aftert the one above. Since the
HTML to create 'form[0]' is after this, it will not exist when the code
runs and is causing an error.

document.getElementByTagName("Finish").click();

Ditto here. To call an element's onclick handler:

document.getElementByTagName("Finish").onclick();


[...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top