A. Askarov
A. Askarov

Reputation: 725

Cant get value from input field

I have an input field with datetime-local type, on editing the form, I cant get the value (which is datetime). In UI, it has the ----- --:--, but when inspecting the code, VALUE parameter has data

Ive tried to document.getElementById().value, $().val(), $().text(), but all of them return "" (empty)

<input type="datetime-local" id="date-from" required="required" value="2019-08-20 05:11:00 UTC" name="pass_request[date_from]">
document.getElementById('date-from').value === ""
$('#date-from').val() === ""
$('#date-from').text() === ""

I value to return, but not emptiness

Upvotes: 1

Views: 51

Answers (1)

Norman Edance
Norman Edance

Reputation: 392

You should format your value according to RFC 3339 as written here - https://www.w3.org/TR/html-markup/datatypes.html#form.data.datetime-local

The following parts, in exactly the following order:
A date.
The literal string "T".
A time.

Example: 1985-04-12T23:20:50.52 1996-12-19T16:39:57

So try

<input type="datetime-local" id="date-from" name="pass_request[date_from]" value="2015-02-15T03:35:00">

Upvotes: 1

Related Questions