0

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.

1
  • 1
    What value are you expecting to put in the input on button click? As there is no code here for us to debug I would suggest you research the click() event handler, and using val() to update the value of your input Commented Apr 11, 2019 at 14:31

1 Answer 1

1

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 )

Sign up to request clarification or add additional context in comments.

7 Comments

This is the way, although I would not recommend to actually make the function trigger on the btn-info class. Neither would I recommend to change the val of every input
Is just an example. It is better to use an id
Yeah I know. Just commenting this in case OP would just copy paste this.
Yes and use like $("#yourID").
Use id selector instead of input.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.