aberdeenphoenix aberdeenphoenix - 1 month ago 8
Javascript Question

Auto-submit the prompt() pop up based on a timer

Ok, I may have found enough information that I should be able to put this together myself, but I just can't.

I'm trying (because reasons) to get string input from users by calling something like this:

var myVar = prompt("Some question?");

I want the prompt popup to automatically submit after, say, 30 seconds. Then I want the script to keep running. I want to use prompt because it's easy. Is there a way to auto submit that based on a timer?

I feel like the key might be somewhere in these two links:
http://www.w3schools.com/js/js_timing.asp
Click a button every second

Do I need to use a popup, not a prompt?
Javascript popups: Submit form, show "wait" screen for 5 seconds, then auto-close popup

Or do I need to use a form?
Auto-Submit Form using JavaScript

Thanks in advance for the help. New user here, and I don't think this question has been answered before.

Answer

Ok, so here's my answer:

  1. Use jQuery
  2. Use Alertify
  3. Use setTimeout

These three things got me where I needed to be; hopefully someone else will eventually stumble on this and get some use out of it.