Link to home
Start Free TrialLog in
Avatar of Chris24
Chris24

asked on

Recipents based on multi-select box

Hi all ...

Here's one for you.

I have a multi-select box containing a list of stores. I have 5 people who each manage a set of stores. How would I easily manage this without 100 if then statements. Here's what I started thinking but then got stumped on how to proceed:

<select name="selStore" size="5" multiple id="selStore">
<option value="GR Clay">GR Clay</option>
<option value="Cascade">Cascade</option>
<option value="Lansing/Edgewood">Lansing/Edgewood</option>
<option value="Kazoo/Sprinkle Rd.">Kazoo/Sprinkle Rd.</option>
<option value="Saginaw">Saginaw</option>
<option value="Muskegon">Muskegon</option>
<option value="Bay City">Bay City</option>
<option value="Jackson">Jackson</option>
<option value="Battle Creek">Battle Creek</option>
<option value="Holland">Holland</option>
<option value="Traverse City">Traverse City</option>
<option value="Cadillac">Cadillac</option>
<option value="Sault Ste Marie">Sault Ste Marie</option>
<option value="Mt. Pleasant">Mt. Pleasant</option>
<option value="Gaylord">Gaylord</option>
<option value="Benton Harbor">Benton Harbor</option>
<option value="Kalamazoo M.H">Kalamazoo M.H</option>
<option value="Lansing Sag Hwy.">Lansing Sag Hwy.</option>
<option value="GR Alpine">GR Alpine</option>
<option value="Alpena">Alpena</option>
<option value="Marquette">Marquette</option>
<option value="Midland">Midland</option>
<option value="Jenison">Jenison</option>
<option value="Petoskey">Petoskey</option>
<option value="Escanaba">Escanaba</option>
</select>

Each user and the index number of each store they would be the recipent of the email if it was selected.

var MPContact1 = new Array(0,1,2,3,6)
var MPContact1Email = "email1@email.com"
var MPContact2 = new Array(4,5,7,8,9)
var MPContact2Email = "email2@email.com"
var MPContact3 = new Array(10,24,11,23,12)
var MPContact3Email = "email3@email.com"
var MPContact4 = new Array(13,14,15,16,17)
var MPContact4Email = "email4@email.com"
var MPContact5 = new Array(18,19,20,21,22)
var MPContact5Email = "email5@email.com"

When the user selects stores in the list, the recipient list is built bassed on which is selected.

Wow! Hard to explain by typing. It is in my head. I hope everyone understands.

Thanks in advance,
Chris24
Avatar of Chris24
Chris24

ASKER

Also, this is only a partial list. The actual list is over 120 items. And the numberr of people could grow or shrink from 2 people to possibly 10.

Thanks,
Chris
ASKER CERTIFIED SOLUTION
Avatar of Batalf
Batalf
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here's the function fromt he code above with some comments

    function sendMail(formObj){
        var sendToAssoc = new Array();
        var sendToString = "";  // Define variable that holds the email addresses
        var selectObj = formObj.selStore;   // Creating reference to select box, ( a shortcut)
        for(var no=0;no<selectObj.options.length;no++){    // Loop through select box options
            if(selectObj.options[no].selected){    // Is this particular option selected?
                for(var no2=0;no2<contacts.length;no2++){    // Loop through contact
                    if(!sendToAssoc[no2]){    // Is this contact allready added to the list, yes? -> Skip it
                        for(var no3=0;no3<contactsIndexes[no2].length;no3++){    // Loop through this contacts indexes
                            if(contactsIndexes[no2][no3]==no){    // This contact has a index matching the current select box index->Add him/her to the recipient list
                                if(sendToString.length>0)sendToString+=";";    // Adding semicolon to the lsit
                                sendToString+=contacts[no2];
                                sendToAssoc[no2]=true;    // Mark this contact as added to the list.
                                break;                                
                            }                            
                        }                        
                    }                    
                }                
            }            
        }
        location.href='mailto:'+sendToString;   // Send email
    }
Avatar of Chris24

ASKER

You rock Batalf!! I wish I could reward more just for how timely your solution was! I appreciate it!

Chris24
Glad I could help!

Batalf