Jump to content

Archived

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

Colleen

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?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Okay, so if I want to have the date automatically entered into the field when any of the four radio buttons are clicked, how would I go about that? The format of the date will be mm/dd/yyyy.

Share this post


Link to post
Share on other sites

<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

Share this post


Link to post
Share on other sites

×

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.