AlisaM
AlisaM

Reputation: 71

How can I have a form field generate the current date and time and then send that information on submit?

I've got a simple registration form, and when the form gets submitted I want to be able to see not just the registrants' basic details but also the date and/or time (at least the date) they registered. I've looked up so many tutorials where JavaScript generates it in the field and it does when I load the form (it's a regular html page, no CMS or database is involved) but after I submit and go to check the registrant details where we keep all the lists, that information isn't there.

Upvotes: 0

Views: 2432

Answers (3)

hima
hima

Reputation: 620

In Javascript,

function generateDate(){
    var currentTime = new Date();                
    var curdate = currentTime.getDate();
    document.getElementbyId("dateHidden").value = curdate;
    return true;
}

Declare this in the form: <input type="hidden" name="Language" id="dateHidden">

<form name="myform" action="JavaScript:generateDate()">

Hope this is what you need.

Upvotes: 1

Mr poppins
Mr poppins

Reputation: 53

        <Script>var currentTime = new Date();                
        var curdate = currentTime.getDate();
        document.getElementbyId("date-of-registration1").value = curdate;
        </script>
        <form>
First name * <input type="text" field_id="262406" name="member_field_first_name" id="id_member_field_first_name" class="input" size="20"/>
Last name * <input type="text" field_id="263430" name="member_field_last_name" id="id_member_field_last_name" class="input" size="20"/>
Email *<input type="text" class="input" name="email" id="id_email" size="20"/>
<input id="date-of-registration1" name="date-of-registration1" class="input" type=hidden/> <input type="submit" name="Submit" value="Subscribe" class="submit">
        </form>

Upvotes: 0

Mr poppins
Mr poppins

Reputation: 53

Server side languages like PHP have built-in functions for Date and Time, That is more reliable as users may not have set proper time on their computers.

Please post your code, it will help us understand better

Upvotes: 0

Related Questions