Removing duplicate values Javascript

  • Thread starter kosta.triantafillou
  • Start date
K

kosta.triantafillou

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
 
K

kosta.triantafillou

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.
 
L

Lee

(e-mail address removed) 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.

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.


--
 
K

kosta.triantafillou

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
 
L

Lee

(e-mail address removed) 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


--
 
B

Bart Van der Donck

[...]
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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top