Jump to content

Automatically enter today's date


Recommended Posts

I have a form that has a group of 4 radio buttons named "Status". I would like to have today's date automatically entered into a field ("DateWonorLost") when the radio button "Won" is clicked (the won button has a value of 2). I have been experimenting with onClick, but am not making any progress. Does someone have any guidance for me? Sample code?

Link to comment
https://forums.phpfreaks.com/topic/1974-automatically-enter-todays-date/
Share on other sites

Dumb question: why not have the date in that field whether they click won, click lost, or do nothing? That way you can populate the field using php server-side, rather than relying on client-side javascript (which might not necessarily be active).

 

Actual php code will vary depending on what date format you want in the field.

<input type="hidden" name="DateWonorLost" value='<?php echo date("m/d/Y"); ?>' />

That will populate the field whenever the form is displayed. If you only want that field to be populated when a radio button is clicked, you'll have no option but to do it with javascript OR have the form resubmit itself. Maybe that'll help

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.