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</o ption>
<option value="Lansing/Edgewood">L ansing/Edg ewood</opt ion>
<option value="Kazoo/Sprinkle Rd.">Kazoo/Sprinkle Rd.</option>
<option value="Saginaw">Saginaw</o ption>
<option value="Muskegon">Muskegon< /option>
<option value="Bay City">Bay City</option>
<option value="Jackson">Jackson</o ption>
<option value="Battle Creek">Battle Creek</option>
<option value="Holland">Holland</o ption>
<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</o ption>
<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</opt ion>
<option value="Marquette">Marquett e</option>
<option value="Midland">Midland</o ption>
<option value="Jenison">Jenison</o ption>
<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
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</o
<option value="Lansing/Edgewood">L
<option value="Kazoo/Sprinkle Rd.">Kazoo/Sprinkle Rd.</option>
<option value="Saginaw">Saginaw</o
<option value="Muskegon">Muskegon<
<option value="Bay City">Bay City</option>
<option value="Jackson">Jackson</o
<option value="Battle Creek">Battle Creek</option>
<option value="Holland">Holland</o
<option value="Traverse City">Traverse City</option>
<option value="Cadillac">Cadillac<
<option value="Sault Ste Marie">Sault Ste Marie</option>
<option value="Mt. Pleasant">Mt. Pleasant</option>
<option value="Gaylord">Gaylord</o
<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</opt
<option value="Marquette">Marquett
<option value="Midland">Midland</o
<option value="Jenison">Jenison</o
<option value="Petoskey">Petoskey<
<option value="Escanaba">Escanaba<
</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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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].s elected){ // 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].lengt h;no3++){ // Loop through this contacts indexes
if(contactsIndexes[no2][no 3]==no){ // This contact has a index matching the current select box index->Add him/her to the recipient list
if(sendToString.length>0)s endToStrin g+=";"; // Adding semicolon to the lsit
sendToString+=contacts[no2 ];
sendToAssoc[no2]=true; // Mark this contact as added to the list.
break;
}
}
}
}
}
}
location.href='mailto:'+se ndToString ; // Send email
}
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.
if(selectObj.options[no].s
for(var no2=0;no2<contacts.length;
if(!sendToAssoc[no2]){ // Is this contact allready added to the list, yes? -> Skip it
for(var no3=0;no3<contactsIndexes[
if(contactsIndexes[no2][no
if(sendToString.length>0)s
sendToString+=contacts[no2
sendToAssoc[no2]=true; // Mark this contact as added to the list.
break;
}
}
}
}
}
}
location.href='mailto:'+se
}
ASKER
You rock Batalf!! I wish I could reward more just for how timely your solution was! I appreciate it!
Chris24
Chris24
Glad I could help!
Batalf
Batalf
ASKER
Thanks,
Chris