Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Client form submit datetime, MVC application

I have an MVC application with a number of forms. When the form is submitted it passed the users gps coordinates to the server. I also want to pass the clients current datetime.

Does anyone have any ideas as to the best way to do this?

The forms are standard html forms and use a basic submit.

My form would look like the one below. So how would I best attach the javascript datetime value to the submit call?

            @using (Ajax.BeginForm("CheckIn", "Home", "Nothing", new AjaxOptions { }))
            {
                <fieldset>
                    <p>Move your Tile here to let those around you see it...</p>
                    <input type="hidden" name="lat" id="hckLat" value="" />
                    <input type="hidden" name="lon" id="hckLon" value="" />
                    <input type="hidden" name="date" id="hckDate" value="" />
                    <input type="submit" value="Check In!" />
                </fieldset>
            }
like image 857
Ben Cameron Avatar asked May 31 '12 14:05

Ben Cameron


1 Answers

You can use JavaScript and the Date function which is rendered on the clients machine.

var d = new Date();

Then you could pass the variable d to the server when you submit the co-ordinates.

From your edit:

In your Checkin method in theHome controller, you could specify:

public ActionResult Checkin(string hckLat, string hckLong, string hckDate) 
{
    var theDate = hckDate;
}

To set the value of hckDate, you could do:

On the submit button click:

<input type="button" name="theSubmitButton" id="theSubmitButton" value="Button"   onClick="setDate();">

function setDate() {
   var e = document.getElementById('hckDate');

   e.value = new Date();
}

This would then be sent to the server.

like image 85
Darren Avatar answered Sep 25 '22 02:09

Darren