Colleen Posted September 28, 2004 Share Posted September 28, 2004 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 More sharing options...
AndyB Posted September 28, 2004 Share Posted September 28, 2004 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. Link to comment https://forums.phpfreaks.com/topic/1974-automatically-enter-todays-date/#findComment-6465 Share on other sites More sharing options...
Colleen Posted September 28, 2004 Author Share Posted September 28, 2004 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. Link to comment https://forums.phpfreaks.com/topic/1974-automatically-enter-todays-date/#findComment-6466 Share on other sites More sharing options...
AndyB Posted September 28, 2004 Share Posted September 28, 2004 <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 Link to comment https://forums.phpfreaks.com/topic/1974-automatically-enter-todays-date/#findComment-6467 Share on other sites More sharing options...
Colleen Posted October 5, 2004 Author Share Posted October 5, 2004 Thanks for your reply, I used your code on one form, but not on another. Link to comment https://forums.phpfreaks.com/topic/1974-automatically-enter-todays-date/#findComment-6500 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.