Removing duplicate values Javascript

Discussion in 'Javascript' started by kosta.triantafillou@gmail.com, May 3, 2007.

  1. Guest

    Hi all,

    I have a form that contains a lot of values. On this form there are
    also alot of popups that can be brought up. One of them does the
    following: Takes 2 values (x and y), concatenates them together with
    an underscore in between and adds them to a select box in the same
    popup (z). Then, when a user clicks a save button located on the
    popup, it sends that information back to the main form and populates
    the same three values (x, y, and z). What I need to do is make sure
    that there are no duplicates in the x and y boxes on the main screen
    before they proceed to the next step.

    Any suggestions?

    Thanks

    Kosta
    , May 3, 2007
    #1
    1. Advertising

  2. Guest

    I forgot to mention....when the values get sent back to the main form,
    they are comma separated. Also, the original x and y values are
    broken down (i.e. split on a comma, then split on the underscore to
    retrieve the original values).

    Thanks.


    On May 3, 9:44 am, wrote:
    > Hi all,
    >
    > I have a form that contains a lot of values. On this form there are
    > also alot of popups that can be brought up. One of them does the
    > following: Takes 2 values (x and y), concatenates them together with
    > an underscore in between and adds them to a select box in the same
    > popup (z). Then, when a user clicks a save button located on the
    > popup, it sends that information back to the main form and populates
    > the same three values (x, y, and z). What I need to do is make sure
    > that there are no duplicates in the x and y boxes on the main screen
    > before they proceed to the next step.
    >
    > Any suggestions?
    >
    > Thanks
    >
    > Kosta
    , May 3, 2007
    #2
    1. Advertising

  3. Lee Guest

    said:
    >
    >I forgot to mention....when the values get sent back to the main form,
    >they are comma separated. Also, the original x and y values are
    >broken down (i.e. split on a comma, then split on the underscore to
    >retrieve the original values).
    >
    >Thanks.
    >
    >
    >On May 3, 9:44 am, wrote:
    >> Hi all,
    >>
    >> I have a form that contains a lot of values. On this form there are
    >> also alot of popups that can be brought up. One of them does the
    >> following: Takes 2 values (x and y), concatenates them together with
    >> an underscore in between and adds them to a select box in the same
    >> popup (z). Then, when a user clicks a save button located on the
    >> popup, it sends that information back to the main form and populates
    >> the same three values (x, y, and z). What I need to do is make sure
    >> that there are no duplicates in the x and y boxes on the main screen
    >> before they proceed to the next step.


    You're going to have to explain more clearly and precisely.
    You haven't told us anything about your "x and y boxes", or
    what it means to "proceed to the next step". I link to a
    page would be helpful, or post the smallest example you can
    contrive.


    --
    Lee, May 3, 2007
    #3
  4. Guest

    I can't really provide a link to this, as it is for a client and it is
    confidential.

    Basically, there are three metadata fields: H Number, PBP Number, and
    Plan Code. The H Number and PBP Number combine together to form the
    Plan Code (i.e. H Number = 111, PBP Number = 222, Plan Code =
    111_222).

    The main form will contain these three boxes:

    Plan Code: __________ [button to click for popup window]
    H Number:_________ [read only text box]
    PBP Number: ________ [read only text box]

    When someone clicks the button next to the Plan Code, it brings up a
    pop window that contains a combo box for both the H Number and PBP
    Number, and a select box for the Plan Code. A user will then enter an
    H Number and PBP Number, and click an Add button located next to it.
    This Add button calls a function that concats the H Number and PBP
    Number together with an underscore in between. At the bottom of the
    popup window is a Save button. Clicking this will send the Plan Code
    information back to the main form. It will also split the Plan Code
    value back into the original H and PBP Numbers and send that back to
    the original form as well. Final result will look like this:

    Plan Code: 111_222
    H Number: 111
    PBP Number: 222

    What I need to do is ensure that there are no duplicate values for the
    H and PBP Numbers on the main form. In other words, it CANNOT look
    like this:

    H Number: 111, 111
    PBP Number: 222, 222

    Any suggestions on how I can filter this out? Should I do it before I
    hit the Save button?

    Thanks alot,
    Kosta

    On May 3, 10:20 am, Lee <> wrote:
    > said:
    >
    >
    >
    >
    >
    >
    >
    > >I forgot to mention....when the values get sent back to the main form,
    > >they are comma separated. Also, the original x and y values are
    > >broken down (i.e. split on a comma, then split on the underscore to
    > >retrieve the original values).

    >
    > >Thanks.

    >
    > >On May 3, 9:44 am, wrote:
    > >> Hi all,

    >
    > >> I have a form that contains a lot of values. On this form there are
    > >> also alot of popups that can be brought up. One of them does the
    > >> following: Takes 2 values (x and y), concatenates them together with
    > >> an underscore in between and adds them to a select box in the same
    > >> popup (z). Then, when a user clicks a save button located on the
    > >> popup, it sends that information back to the main form and populates
    > >> the same three values (x, y, and z). What I need to do is make sure
    > >> that there are no duplicates in the x and y boxes on the main screen
    > >> before they proceed to the next step.

    >
    > You're going to have to explain more clearly and precisely.
    > You haven't told us anything about your "x and y boxes", or
    > what it means to "proceed to the next step". I link to a
    > page would be helpful, or post the smallest example you can
    > contrive.
    >
    > --- Hide quoted text -
    >
    > - Show quoted text -
    , May 3, 2007
    #4
  5. Lee Guest

    said:
    >
    >I can't really provide a link to this, as it is for a client and it is
    >confidential.
    >
    >Basically, there are three metadata fields: H Number, PBP Number, and
    >Plan Code. The H Number and PBP Number combine together to form the
    >Plan Code (i.e. H Number = 111, PBP Number = 222, Plan Code =
    >111_222).
    >
    >The main form will contain these three boxes:
    >
    >Plan Code: __________ [button to click for popup window]
    >H Number:_________ [read only text box]
    >PBP Number: ________ [read only text box]
    >
    >When someone clicks the button next to the Plan Code, it brings up a
    >pop window that contains a combo box for both the H Number and PBP
    >Number, and a select box for the Plan Code. A user will then enter an
    >H Number and PBP Number, and click an Add button located next to it.
    >This Add button calls a function that concats the H Number and PBP
    >Number together with an underscore in between. At the bottom of the
    >popup window is a Save button. Clicking this will send the Plan Code
    >information back to the main form. It will also split the Plan Code
    >value back into the original H and PBP Numbers and send that back to
    >the original form as well. Final result will look like this:
    >
    >Plan Code: 111_222
    >H Number: 111
    >PBP Number: 222
    >
    >What I need to do is ensure that there are no duplicate values for the
    >H and PBP Numbers on the main form. In other words, it CANNOT look
    >like this:
    >
    >H Number: 111, 111
    >PBP Number: 222, 222
    >
    >Any suggestions on how I can filter this out? Should I do it before I
    >hit the Save button?


    I still don't know enough to give a detailed answer, but
    at some point you need to maintain a list of values that
    have already been added, and compare the new values to
    each element in the list. Is it pairs of numbers (eg 111_222)
    that you want to avoid duplicating, or individual numbers.
    For example, could you have plan codes 111_222 and 111_333,
    and, in that case, do you allow:
    Plan Code: 111_222, 111_333
    H Number: 111
    PBP Number: 222, 333


    --
    Lee, May 4, 2007
    #5
  6. wrote:

    > [...]
    > What I need to do is ensure that there are no duplicate values
    > for the H and PBP Numbers on the main form. In other words,
    > it CANNOT look like this:
    > H Number: 111, 111
    > PBP Number: 222, 222


    var P = ['11, 22', 'def, def', 'q,q', 'AG, Ag', '111, 111']
    display(P)
    var newP = new Array()
    for (var i = 0; i<P.length; ++i) {
    var spl = P.split(', ') // space after comma
    if (spl[0] != spl[1])
    newP.push(P);
    }
    display(newP)

    function display(arr) {
    document.write('<hr>')
    for (var j = 0; j<arr.length; ++j)
    document.write(arr[j]+'<br>');
    }

    Hope this helps,

    --
    Bart
    Bart Van der Donck, May 5, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sumit
    Replies:
    1
    Views:
    6,448
    Anatoly
    Nov 25, 2003
  2. Replies:
    5
    Views:
    2,321
    Andrey Kuznetsov
    Apr 5, 2006
  3. wooks
    Replies:
    3
    Views:
    533
    wooks
    Jul 22, 2004
  4. sri2097
    Replies:
    4
    Views:
    576
    sri2097
    Jan 10, 2006
  5. Replies:
    2
    Views:
    557
    Andy Dingley
    Dec 6, 2006
Loading...

Share This Page