Forum Moderators: open

Message Too Old, No Replies

Auto form submission?

         

glamdring

4:43 pm on Jun 16, 2004 (gmt 0)

10+ Year Member



Could anyone tell me if its possible to have a form automatically submit itself after a certain period of time - say 2 seconds - has expired?

j4mes

4:48 pm on Jun 16, 2004 (gmt 0)

10+ Year Member



Yup! Try this:

<script type="text/javascript">
setTimeout("your_form_name.submit()", 2000);
</script>

The number (2000) is milliseconds, so 2000 = 2 seconds.

J.

glamdring

6:44 pm on Jun 16, 2004 (gmt 0)

10+ Year Member



Thankyou!

Out of interest, is it possible without using JScript?

j4mes

6:58 pm on Jun 16, 2004 (gmt 0)

10+ Year Member



You're welcome :)

I expect there is, but not one I know of!

The problem is that most other scripting languages are server side, so can't be used after the page has loaded.

glamdring

7:52 am on Jun 17, 2004 (gmt 0)

10+ Year Member



J4mes, thanks again :

have you any idea why this works OK in IE but not Netscape?

Is it possible to put an alternative text in for Netscape users?

j4mes

4:07 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



Hmmm, that's bad, I didn't know it didn't work in Netscape. Which version btw?

I'll look into it now and post again in a bit :)

glamdring

4:21 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



7.1, downloaded it a couple of days ago.

j4mes

5:05 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



The following worked in Netscape 4.6, so should be alright :) (extremely basic I know!)

<html>
<head>
<title>Auto Submit Thingy</title>
</head>
<body>

<script type="text/javascript">

setTimeout("SubmitThingy()",5000);

function SubmitThingy() {
document.FormThingy.submit();
}

</script>

<form name="FormThingy" method="post" action="CGI SCRIPT GOES HERE">

<input type="text" name="TextThingy" value="Type Here">
<input type="submit" value="Submit">

<p>Click Submit or wait 5 seconds.</p>
</form>

</body>
</html>

Does it work OK in 7.1?

glamdring

5:37 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



Yep, magic.

Thanks a lot.