jaggernat
asked on
removing duplicates in javascript
Dear experts,
I have a field in my jsp page which is
<html:select property="addtlFacs" styleClass="formstyle" multiple="true" size="8" style="width:80">
<html:optionsCollection property="allAddtlFacs" value="value" label="label"/>
</html:select>
<a href="javascript:dedupe_li st('addtlF acs');">Re move duplicates</a>
and i have a link "Remove Duplicates" below that field which removes duplicates.the method passes
the property "addtlFacs" as parameter . I am able to get that property in my javascript file,but
unable to remove duplicates from the field. I tried to use a bunch of javascript functions which i
found online but no luck.
any help would be greatly appreciated.
thanks
J
I have a field in my jsp page which is
<html:select property="addtlFacs" styleClass="formstyle" multiple="true" size="8" style="width:80">
<html:optionsCollection property="allAddtlFacs" value="value" label="label"/>
</html:select>
<a href="javascript:dedupe_li
and i have a link "Remove Duplicates" below that field which removes duplicates.the method passes
the property "addtlFacs" as parameter . I am able to get that property in my javascript file,but
unable to remove duplicates from the field. I tried to use a bunch of javascript functions which i
found online but no luck.
any help would be greatly appreciated.
thanks
J
You want to remove duplicate options from the select field ?
ASKER
yes
It would be good to have a button that would call that function.
Perhaps like this:
<html:select property="addtlFacs" styleClass="formstyle" multiple="true" size="8" style="width:80">
<html:optionsCollection property="allAddtlFacs" value="value" label="label"/>
</html:select>
</html:button onClick="dedupe_list(this, 'addtlFacs ');" label="Remove duplicates" /a>
Let the html be generated for that page and copy that html source snippet to EE for furter coding.
Perhaps like this:
<html:select property="addtlFacs" styleClass="formstyle" multiple="true" size="8" style="width:80">
<html:optionsCollection property="allAddtlFacs" value="value" label="label"/>
</html:select>
</html:button onClick="dedupe_list(this,
Let the html be generated for that page and copy that html source snippet to EE for furter coding.
ASKER
ok "viewsource" (html source) for "addtlFacs" field yeilds this
<select name="addtlFacs" multiple="multiple" size="5" tabindex="24" style="width:170" class="formstyle"></select >
<select name="addtlFacs" multiple="multiple" size="5" tabindex="24" style="width:170" class="formstyle"></select
There are no <option>s, but anyway, what do you like to compare for same options? Option text or option values?
OK, the JSP button is something like this:
<HTML:button property="removeDuplicates " value="Remove duplicates" styleClass="buttonNew" onclick="dedupe_list(this, 'addtlFacs ');" />
<HTML:button property="removeDuplicates
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
My is more simple (or less complicated :)
<script>
function dedupe_list(theSel){
var unq = new Array();
var opt = theSel.options;
for(var i=0;i<opt.length;i++){
unq["_"+opt[i].value] = opt[i].text;
}
opt.length=0;
for(v in unq){
opt[opt.length] = new Option(unq[v], v.substr(1));
}
}
</script>
And the button is simelar to above propsed:
<HTML:button property="removeDuplicates " value="Remove duplicates" styleClass="buttonNew" onclick="dedupe_list(this. form.addtl Facs);" />
<script>
function dedupe_list(theSel){
var unq = new Array();
var opt = theSel.options;
for(var i=0;i<opt.length;i++){
unq["_"+opt[i].value] = opt[i].text;
}
opt.length=0;
for(v in unq){
opt[opt.length] = new Option(unq[v], v.substr(1));
}
}
</script>
And the button is simelar to above propsed:
<HTML:button property="removeDuplicates
Sorry, now I see. My version is NOT less complicated. Your is even better because it does not recreate the Options like my version does.
Thanks for the compliment :)
ASKER
wow. that was just perfect.
thanks
thanks