0

I do not know much about html. I have a simple web page for multiple choice answers, this format:

a question, 4 radio buttons
a question, 4 radio buttons

and so on.

At the bottom is a send button to send the input to my email, where I use python to parse the input. This works ok.

<input type="submit" value="Send Form">

What I want is a timeout on the send button, so that, say after:

18:00 Friday 19th October 2018

the send button is deactivated. I'd like a little message to appear, something like "You are too late, I said hand in your homework by 6 o'clock Friday."

I will be very grateful for any tips on how to achieve this. PHP? Javascript?

Pedroski
  • 433
  • 1
  • 7
  • 16
  • Possible duplicate of [run code depending on the time of day](https://stackoverflow.com/questions/8652502/run-code-depending-on-the-time-of-day) – Quentin Veron Oct 16 '18 at 22:40
  • This feels like an XY problem: https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem Using client side code to control submission can be bypassed. – Jason Aller Oct 16 '18 at 23:10
  • OK, that would put out a message, but could the send button be disabled or removed? Something like: "if time > Friday 6pm: del in PHP?? Otherwise, I'll just ignore emails sent after that time, probably easier. – Pedroski Oct 17 '18 at 01:43

2 Answers2

1

I am new and i can't add a comment. I hope that this link help you:

This post talks about timer... Enable button when counter reaches zero

With some modifications you can use it for your purpose.

Ferdinando
  • 964
  • 1
  • 12
  • 23
1

The demo below checks the current date and time against October 19 2019, 18:00. If the current date and time is later than this, then the submit button is disabled and a message is displayed explaining why. I've also attached to the submit button the function that does the check. This is for cases where the user landed on the page before the deadline, but the time expires while they're on and they were not able to submit in time. In such a case, the form submission is deferred to the same function, and it will prevent the form submission if the deadline has lapsed. You can test this out by changing the variable "terminate" to an earlier date, like October 16. You can also comment out the call to the checkForExpiration() function in the start() to test the form submission part.

var expMsg = document.getElementById("expireMsg");
var subBtn = document.getElementById("subBtn");
var terminate = new Date("October 19, 2018 18:00:00");
//
function start() {
  checkForExpiration();
}
//
function checkForExpiration() {
  expMsg.innerHTML = "";
  subBtn.disabled = false;
  var currentDate = new Date();
  //
  if (currentDate > terminate) {
    subBtn.disabled = true;
    expMsg.innerHTML = "Sorry, but you've missed the deadline";
    return false;
  } else {
    return true;
  }
}
//
window.onload = start();
<form name="myForm" onsubmit="return checkForExpiration();">
  <input id="subBtn" type="submit" value="Send Form">
</form>
<div id="expireMsg"></div>
MichaelvE
  • 2,558
  • 2
  • 9
  • 18
  • Thank you very much. I'll try to apply it with my limited skills. Let you know if I get it working, thanks – Pedroski Oct 17 '18 at 12:45
  • I'm unsure where to put the above code. Inline in the webpage html code? Just above the
    code?? Sorry, but I don't know much about this, I just copy a bit of code here and there, try to make it work.
    – Pedroski Oct 20 '18 at 09:05
  • I would put the JavaScript code between script tags before the close body tag – MichaelvE Oct 21 '18 at 01:17
  • I just want to say it works perfectly for me! Thank you very much! – Pedroski Nov 01 '18 at 23:24