Loading ...
Sorry, an error occurred while loading the content.

string to time without date conversion

Expand Messages
  • h3lga2002
    To Whom It May concern I have the following urgent problem: I have a few edit boxes with text in it which represents durations (time) in the following format:
    Message 1 of 2 , Apr 19, 2002
    • 0 Attachment
      To Whom It May concern

      I have the following urgent problem:

      I have a few edit boxes with text in it which represents durations
      (time) in the following format: hh:mm:ss.

      I have to work with these pre-entered values and have a total field
      named TotTTimes which is added up from 3 fields called TotBTime,
      TotPTime, TotUTime.

      The value of these three fields (TotBTime, TotPTime, TotUTime) are
      recalculated depending on selections made by the user.

      When the user selects B (via a radio button) on the first line, the
      value of one of the above mentioned 3 fields changes. i.e. on the
      first row U was selected. Now he/she selects B. The value of the
      TimeOne edit box (pre-entered and not editable) has to be subtracted
      from TotUTime and added to TotBTime.

      I have no problem with the actual calculation code. What is creating
      a problem is the calculation reads the value of all the edit boxes as
      strings. I can not use parseInt(TimeOne.value) or even parseFloat
      (TimeOne.value).

      What must I use or how can I convert the data in the textbox to time
      format?

      Your assistance will highly be appreciated.

      Helga
    • davidblackledge
      (dangit... the default for these is coming up as sending to the person who wrote it... not the whole group... this is hard to remember... I wonder if others
      Message 2 of 2 , Apr 23, 2002
      • 0 Attachment
        (dangit... the default for these is coming up as sending to the person
        who wrote it... not the whole group... this is hard to remember... I
        wonder if others are having this problem and not realizing it... I
        just posted a reply to someone about the "access denied" problem, but
        I don't think it'll show up here.)

        Ok, if I understand correctly, you need to do some math where you have
        several values in the format "hh:mm:ss"... and of course there's no
        "parseTime" function. Since you say you're fine with the rest of the
        calculation, I'll just give you what you need to start calculating:

        var timeValsArray = TimeOne.value.split(":");
        var hours = parseInt(timeValsArray[0],10);
        var mins = parseInt(timeValsArray[1],10);
        var secs = parseInt(timeValsArray[2],10);

        voila!

        the "10" parameter forces parseInt to work in base 10... otherwise,
        when it saw e.g. "09" seconds, it would think the value was in octal,
        and 9 is invalid for octal, so you'd get NaN or 0 or something
        similar.

        David.
        http://David.Blackledge.com

        --- In javascript3@y..., "h3lga2002" <helga@k...> wrote:
        > To Whom It May concern
        >
        > I have the following urgent problem:
        >
        > I have a few edit boxes with text in it which represents durations
        > (time) in the following format: hh:mm:ss.
        >
        > I have to work with these pre-entered values and have a total field
        > named TotTTimes which is added up from 3 fields called TotBTime,
        > TotPTime, TotUTime.
        >
        > The value of these three fields (TotBTime, TotPTime, TotUTime) are
        > recalculated depending on selections made by the user.
        >
        > When the user selects B (via a radio button) on the first line, the
        > value of one of the above mentioned 3 fields changes. i.e. on the
        > first row U was selected. Now he/she selects B. The value of the
        > TimeOne edit box (pre-entered and not editable) has to be subtracted
        > from TotUTime and added to TotBTime.
        >
        > I have no problem with the actual calculation code. What is
        creating
        > a problem is the calculation reads the value of all the edit boxes
        as
        > strings. I can not use parseInt(TimeOne.value) or even parseFloat
        > (TimeOne.value).
        >
        > What must I use or how can I convert the data in the textbox to time
        > format?
        >
        > Your assistance will highly be appreciated.
        >
        > Helga
      Your message has been successfully submitted and would be delivered to recipients shortly.