O San
O San

Reputation: 83

How can I POST the value into the input box using JQuery or Js?

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>:&nbsp&nbsp
<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

Answers (1)

Andrei Lupuleasa
Andrei Lupuleasa

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

Related Questions