Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help parsing data

    Anyone that can help on this one it would be greatly appreciated...

    I need to make a form parses a result from column 1 of txt/csv file that has 7 columns. Column 1 is pay, column 2-7 are how many and the associated rows are the answers. In short
    1 2 3 4 5 6
    700 50 55 62 75 80 99

    so if the customer enters i make 700 and i need 2 the result would be 55 as the output. Any idea on how to make that work with javascript?

    if (pay <=700 && widgets = 2)
    {
    document.write(55)
    elseif (pay <=700 && widgets = 1)
    document.write(50)
    is this doable and is it the easiest way to accomplish this?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Not to ask a silly question, but... How are you getting the data from that file into the HTML page for JS to parse?

    Are you using xmlhttp and getting it all in a big responseText string?

    And what is the *specific* format of the file? You say CSV, so is it really commas? Is it commas and quotes?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it can be a comma file or an excel file. The input would come from the user ie: enter your pay.... take that input and run it against the table(file) and then ask the need of 1 to 6 and that produces the number from the table ( kinda like parsing the tax table if you will ...

    the above is the concept. would this be easier to build arrays for each possibility? 1000 and 1 = $$ 1000 and 2 = $$ etc?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Oh. you definitely want it to be done via arrays.

    But you have to parse the file to create the data elements that you will put into the arrays (well, probably one array...an array of objects).

    So what is it you need help with??? If it's parsing the file, then you have to show some examples of the actual lines in the file.

    I would think that, after you have parsed the data, the code to scan the array for the match on user input is trivial. A handful of lines.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe this is easier...
    How do I accomplish a drop down populated with possible pay (dollar amounts since they have to round up anyways) and another drop down that has the number 1 -6 and based on the two combined it produces the amount owed. So 1000 dollars and claiming 1 is x 1000 dollars claiming 2 is x

    That was I just populate what would be in the table into an array of values right?

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    OH! Income tax.

    Income vs. number of deductions produces how much tax is owed.

    Yeah, you could use dropdowns, but you still need the "lookup table".

    You surely don't want to do this as a mass of "if" tests.

    Creating the array--however you do it--is the first step. And parsing a CSV file is a fine way to create the array. It has the huge advantage that all you have to do to change things is drop in a new CSV file.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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