1

This is a question of how to do it without JavaScript

Imagine JavaScript is disabled in the browser. Is there a way for us to understand the current time on the user machine?

For example can we ask the browser to fill a hidden field in a form?

eglease
  • 2,445
  • 11
  • 18
  • 28
kmitov
  • 1,243
  • 3
  • 11
  • 25
  • What would you do with it? Submit the form? – trincot Oct 24 '21 at 19:50
  • I have users in different time zones. I would like to answer the question: "How many files do users generally upload in the morning" This means their morning. And yes, submit the form would be perfect. – kmitov Oct 24 '21 at 19:52
  • @trincot the one you are referring - the answers are "with" javascript. In my case javascript is disabled in the browser. So there is No javascript. I am looking for a way without javascript. – kmitov Oct 24 '21 at 19:55
  • The answer (also mentioned [there](https://stackoverflow.com/a/3724089/5459839)) is that without JS this is not possible. – trincot Oct 24 '21 at 19:58
  • yes, you are right. Found the answer that it is not possible. – kmitov Oct 24 '21 at 20:01

1 Answers1

0

You can set the date in a text input like so:

<input type="date" value="2021-10-24" />

However, there's no way to automatically populate that value on the browser side without using JavaScript. That means if you need this to work you'd have to use PHP or some other server side implementation to pre-fill the input with the current date when it's served to the client. Obviously this could have timezone implications and would not be the date on the user's machine, but is probably as close as you'd be able to get with JS disabled.

Mordred
  • 3,734
  • 3
  • 36
  • 55
  • I can pre-fill the input field on the server and serve it to the client. I can set it to value=Time.now where Time.now is UTC time on the server. But when getting it back I still cant find a way to get understand the timezone of the user – kmitov Oct 24 '21 at 19:49
  • Yup, there's no way to get any of that information without javascript. – Mordred Oct 25 '21 at 03:55