3

I am trying to get the Date and Time from the user and want to submit it to Parse.com. But when I am facing the problem with the following code

What mistake am I doing here?

<div id="main">
 <form name="myForm" action="" method="get">
 Date: <input type="datetime-local" name="datentime" id="theDate">
<input type="submit" value="Submit" onclick="myFunction()">
</form> 

and the javascript code

function myFunction()
{
    var TestObject = Parse.Object.extend("TestObject");
    var testObject = new TestObject();  
    var date = new Date();
    date = document.getElementById("theDate").value; //document.forms["myForm"]   ["datentime"].value; /*new Date();*/

    testObject.set("myDate", date);
    testObject.save(null, {
    success: function(testObject) {
        $(".success").show();
    },
    error: function(testObject, error) {
        $(".error").show();
    }
    });
}

In above line testObject.set("myDate", date); this like is not working.I am not sure how to take the input from the date and give it to the parse.com where the column name is myDate of type Date If I try testObject.set("foo","testing...") where foo is column name of type string.It's working properly

4
  • Can you include any error you're getting or be more specific as to what issue you're encountering? Commented Jul 8, 2013 at 18:57
  • @HectorRamos : testObject.set("myDate", date); this like is not working.. I am not sure how to take the input from the date and give it to the parse.com where the column name is myDate of type Date.. If I try to testObject.set("foo","testing...") where foo is column name of type string ..its working properly Commented Jul 9, 2013 at 3:39
  • have you tried using just date - not setting it to the document.getElement... Just date = new date() then set it? If that works then you know where the issue is Commented Jul 9, 2013 at 3:59
  • @nycynik : then its working properly. I have checked that, but not sure why can't it take that value Commented Jul 9, 2013 at 13:11

1 Answer 1

4

Your issue is just with the way that you are creating a date. I would think that it should work, but is it possible that it is creating a string object?

try checking the type of date it should show an object, if it does not, then the date is not a date, but just a string:

console.log(typeof(date));

Also try to log the value:

console.log(document.getElementById("theDate").value); 
Sign up to request clarification or add additional context in comments.

1 Comment

Yo thanks dude... Yes its coming in the string format ... I made the correction here it is ...var date_str = document.getElementById("theDate").value; var date = new Date(date_str);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.