Jump to content
xisto Community
xJedix

Javascript Question

Recommended Posts

Alright, I am trying to make this code do a loop so that it submits the form every 30 minutes. I have tried using a while loop but it only does it once.

This is what I am trying to do every 30 minutes.

setTimeout('document.upgradeForm.submit()',1800000);

Right now, it submits the form after 30 minutes only one time.

This is what I tried to do, since infinite loops freezes your browser, I set it to do it for a 100 times :\

var x=0while (x<=100){setTimeout('document.upgradeForm.submit()',1800000);x = x+1}

I believe I need to some how tell it to wait the 30 minutes before repeating the loop, but I don't know how to do that. If you know how, or know a better way to accomplish this.... please reply.

Thanks, xJedix

Share this post


Link to post
Share on other sites

Can I first of all ask why?  Secondly if the submitting was to be a personal thing then I would recomend making use of a cronjob rather then Javascript.

191156[/snapback]


Welll, I play a game called darkthrone... You might have heard of it. I am making this so it will buy me items every 30 minutes, which is when I get more gold.

 

I haven't used cronjobs before, if you could explain how to do this with cronjobs, it would be greatly appreciated.

 

xJedix

Share this post


Link to post
Share on other sites

If you want to use a cron job, first you have to have hosting, usually linux, that supports cron jobs. Then, though something like cPanel, you can set up a cron job to automatically run a script (in this case your form, which you could just make a PHP or other type of script to post the variables to wherever is needed) every half hour (or whatever length of time you want). If you need more help on the details, don't hesitate to ask! Hope you get it working soon!!

Share this post


Link to post
Share on other sites

Alright, I am trying to make this code do a loop so that it submits the form every 30 minutes.  I have tried using a while loop but it only does it once.

 

This is what I am trying to do every 30 minutes.

 

setTimeout('document.upgradeForm.submit()',1800000);

Right now, it submits the form after 30 minutes only one time.

 

This is what I tried to do, since infinite loops freezes your browser, I set it to do it for a 100 times :\

 

var x=0while (x<=100){setTimeout('document.upgradeForm.submit()',1800000);x = x+1}

I believe I need to some how tell it to wait the 30 minutes before repeating the loop, but I don't know how to do that.  If you know how, or know a better way to accomplish this.... please reply.

 

Thanks, xJedix

191092[/snapback]


have you tried to break your loop and run a timer that continues the loop after 30 mins. I don't know if it would work and don't have the time to try it right now. But try it out and let me know.

 

when I get more time I will try too.

Share this post


Link to post
Share on other sites

Indeed, just let a timer run, 12:xx:21

and when the xx = 00 OR 30 ... just send your form!

Share this post


Link to post
Share on other sites

setInterval might be a better choice when you want a chunk of code to run repeatedly. But for a script running in a browser, 30 minutes might as well be 30 years. You may well get that annoying box warning about long script execution times. Maybe not, though, because the script is "idling." It'd be an interesting experiment anyway, despite the fact that there are likely better ways to accomplish it than by using javascript.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.