Help with Split() function

Results 1 to 2 of 2

Thread: Help with Split() function

  1. #1
    Join Date
    Dec 1969

    Default Help with Split() function

    i am using this function to extract data from a text box, i need it to be this sort of function cuz i need ot extract several dates and do subtractions on them. teh prob is, i want a dash also to be a splitter along with a slash. now i dont knwo how teh format woudl be in () section of the code<BR><BR><BR>var arrField1 = dtDateJoined.split("/");<BR>

  2. #2
    Join Date
    Dec 1969

    Default Looks right to me...

    ...what isn&#039;t working?<BR><BR>Note that dtDateJoined *must* be a string, but if it came from a form field value of any kind, it will be. But then you named it wrong: "dt"??? If it&#039;s a *STRING*??? By definition you can NOT use split on anything but a String object.<BR><BR>OH! Sorry! I re-read the question.<BR><BR>I&#039;d do this:<BR><BR> strDateJoined = document.FormName.FieldName.value;<BR> strDateJoined = strDateJoined.replace( /[-s.\]/g, "/" )<BR> arr = strDateJoined.split("/");<BR><BR>Could do it all in one big ugly line:<BR><BR> arr = document.FormName.FieldName.value.replace( /[-s.\]/g, "/" ).split("/");<BR><BR>The trick: First convert *any* separator the user might have used to the slash. That replace will convert - and space and . and all to / for the split.<BR><BR>

Posting Permissions

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