I want to have two select tags in html, one for hour and one for minutes. I want the default value of hour to be set on current hour and the value of minute to be set on current minute. I think with default time to be set for example on 3, i should have some thing like this:
<select name="hour">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3" selected="selected">3</option>
<option value="4">4</option>
...
<option value="23">23</option>
</select>
now my question is how can i use javascript to show the current hour and minutes by default?
Depending on how you’re creating the
optionelements, one approach is to use:JS Fiddle demo.
This uses the JavaScript
Date()methods,getUTCHours()If your
optionelements are already set in the HTML, and you’re simply changing which isselectedby default:JS Fiddle demo.
References:
Date().