mannyotr
mannyotr

Reputation: 83

Update Time Element with Javascript

I am using this code to display two fields. One is type=time and the other is type=text.

Using the button and javascript code I am trying to update the values in the fields.

It works perfectly for the text field, but I can't for the life of me get it to work on the time field.

<html>
<body>

<input type="button" name="now" value="in" onclick="settime();" />
<input type="time" step=1 size=10 id="timein" name="timein">

<br /><br />

<input type="button" name="now" value="in" onclick="settext();" />
<input type="text" size=10 id="timetext" name="timetext">

<script>

function settime(){
    document.getElementById("timein").value = "10:13:43 AM";
}

function settext(){
    document.getElementById("timetext").value = "10:13:43 AM";
}

</script>

</body>
</html>

Can anyone please point out my mistake?

Thanks in advance!

Upvotes: 1

Views: 97

Answers (1)

toskv
toskv

Reputation: 31600

You can not set the AM/PM part of the time. Instead use the 24 hour format to specify that.

function settime(){
    document.getElementById("timein").value = "10:13:43";
    console.log(document.getElementById("timein"))
}

Check out how the Input Time Value works here: http://www.w3schools.com/jsref/prop_input_time_value.asp

Upvotes: 2

Related Questions