Jump to content

getting input from user without submitting to a server


Liquid

Recommended Posts

Hi, so im eventually gonna try to compare two user entered dates and determine which is greater then the other, i assume i can just do that part with parse and get the ms since 1970, the part im having difficulty with is take the input from the input boxes and using those as the dates. all the tutorials and information ive found sends it to a server database to get info, i just want to almost turn them into a string. i know how to do this in java, but im lost as to how to do this in javascript.Any help would be appritiated

Link to comment
Share on other sites

what have you attempted so far? Are you validating submitted values as far as submissions go? I think the most challenging part would be parsing the date entered into a format acceptable to the date object, but you can setup your form and use a simple regex to make sure you are only getting numbers, and that you know which parts of the date users are entering, relative to which parts of the date you are asking from them.For example, you can pass the date object a date string to get the date, and the use getTime() to get the millis from 1970 and then compare the returned values against each other to see which one is greater.http://www.w3schools.com/js/js_obj_date.asp

Link to comment
Share on other sites

I've done some testing with dates in JavaScript, and I've found the following formats to work well:mm/dd/yyyyyyyy/mm/ddm/d/yyyyyyyy/m/dmm/dd/yy *m/d/yy *monthname dd, yyyymonthabbr dd, yyyy*NOTE - Two-Digit years do not quite work as expected.For example: 7/21/09 will be interpreted as July 21, 1909 instead of 2009You could use a regex to compare the user input to one of these strings, and if it's a match, parse it into a date.

Link to comment
Share on other sites

I was thinking you could segment out each part of the date as an input (and any parts not left in could default to 0). i.e. an input for month, day, year, etc. You can translate the string values into numbers, or vice versa. I think it all depends on your UI and how you are presenting it the user, and how they will be entering the dates. I was thinking you could use regex just make sure each input is a number. ORyou could just use drop downs so that way you have control over the input and validation wouldn't have to be so much of a concern. From the drop down you get a standardized input value that you can use in a generic date constructor function, put it together, and then pass it as string into the Date object, get the time in millis out, and compare.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...