SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot andyy15's Avatar
    Join Date
    Oct 2004
    Location
    USA
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parse Text Field Date

    I have a Text Field that displays dates in this format: January 1, 2008
    These dates are calculated using a function that adds years to a user input start date. How do I take the contents of that Text Field and parse it into 3 variables to be used in another function?

    Example:
    var year = 2008
    var day = 1
    var month = January
    (except these months, days and years will change based on the value of the Text Field)

    Thanks in advance for you help.
    My Jewelry Website (Nita Creations Jewelry): NCJ.US
    Visit Avid Website Design

  2. #2
    SitePoint Member
    Join Date
    Jul 2007
    Location
    New York, NY
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    assuming you are somehow ensuring the user enters the date in that exact format, you can split the string into an array, based on the spaces between the month-day and day-year, like this:
    var myArray = textfield.split(" ");

    once you have the array, you can loop through it, doing whatever it is you want to do with the 3 pieces of data, like this:
    for (var i=0; i < myArray.length; i++)
    // do your stuff here

    hope this helps,
    Atg
    Aaron T. Grogg
    aarontgrogg.com/


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •