Reputation: 83
From my earlier post (How I can POST the value into input box?), one of the comment suggested me to do it in JQuery or Javascript.
More code and info, you can access it in the above link that I provided.
<label>Date</label>:  
<input style="font-size:22px" size="20" type="text" name="datetime" value="" placeholder="Click to get current time." required readonly>
<button style="font-size:1em" type="submit" name="Time" class="btn btn-info">
Click <i class="far fa-clock"></i>
</button>
After click at the button I expect that the value will be parsed into the input text box which I set it as readonly
to prevent improper input from the user/admin.
Upvotes: 0
Views: 34
Reputation: 2762
Use:
var today = new Date();
var currentTimeValue = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate() + " " + today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
$(".btn-info").click(function() {
$("input").val(currentTimeValue);
})
You should use ids in order to don't modify the first input inside the dom. (to avoid possible bugs )
Upvotes: 1