This might be an incredibly easy problem to fix, but I’m not quite sure what to do. Been looking around the net and have come up pretty empty, so I was hoping someone would be kind enough to help me out. I’ve never used JS/JQuery much, but I have a small task I need to get done.
There is a dropdown menu with a list of twenty or so options . I need to write a function that selects a specific list of them and adds them to another list I have.
So far I have this (keep in mind I didn’t write most of this; the guy who did is out and I have to get this done, or else I’d just wait and ask him):
[CODE]
$(“#button”).click(function(event){
var itemValue = $(‘#dropdownMenu’).val()
var defaultValues = [1001,1012,1009,1011,1014,1026,1030,1041,1017]
// this list of values is a partial list of everything in dropdownMenu
// I want to add these to otherList, below
var otherList = $(“#otherList”).val().split(“|”)
$.each(defaultValues, function(itemValue) {
if(jQuery.inArray(itemValue, otherList) < 0) {
itemText = $(“#dropdownMenu :selected”).text();
idx = $(“#dropdownMenu”).attr(“selectedIndex”);
$(‘#someTable tr:last’).after(‘<tr id=”ar_’ + idx + ‘”><td>’ + itemText + ‘</td></tr>’);
$(‘#otherList’).val($(‘#otherList’).val() + ‘|’ + itemValue);
if ($(‘#otherList’).val().charAt(0) == “|”) {
$(‘#otherList’).val($(‘#otherList’).val().replace(‘|’, ”));
}
}
});
});
Now, obviously this just adds the dropdownMenu value eight times to the list because it’s just using the value of whatever is selected in the menu, rather than the defaultValues list that I want (the original function was just adding the selected item; I am adding the #button and new code to add the defaultValues list to otherList). Just not quite sure how to get the value and text from my defaultValues array in order to display them correctly in that otherList array.
If this isn’t clear, I can try to clarify if needed. Thanks for any help. ?