Hello all…
This is for the Web. using javascript.
I have a textbox, Button, and a Listbox.
The button is used to Add whatever Text is in the textbox into the listbox.
The listbox is also populated by @DbColumn.
However i dont want the user to be able to add duplicates.
I’m guessing i have to loop through the listbox and check to see if whatever is in the Textbox does not Equal anything in the listbox.
I can’t figure it out, i’ve tried a few different things, but no luck.
Any help would be apprecaited, thanks!
-Jordan
Subject: Looping through a Listbox
How about the follwing code, placed in the onClick event of your button:
var frm = document.forms[0];
var tfield = frm.textFieldName; //use your text field name
var lbox = frm.listBoxName; //use your list box name
var flag=false;
for(i=0;i<lbox.options.length;i++) {
if (lbox[i].text==tfield.value){
flag=true;
break;
}
}
if (flag) {
alert(‘Duplicate item!’);
}
else {
lbox.options.length++;
lbox[lbox.options.length-1].text = tfield.value;
}
Subject: RE: Looping through a Listbox
Excellent, thankyou so much!!
Subject: It’s Not even that tough!..java script not needed…
When you have a list box of multiple values… each value is an Element… if you use the @Subset command in conjuction with the @IsMember command, you can determine is a string of text (the value of the field) is already a Member of the ListBox values before it’s added
@If(!@IsMember(ListBoxField;textfield);@SetField(ListBoxField;Listboxfield:textfield);“”)
Seems a bit shoreter than all that java script.
Ruth