0

I have list of groups:

 <select multiple="multiple" name="groups[]" id="groups[]" class="myclass">
<option value="1">Employee</option> 
<option value="2">Suppliers</option>
<option value="3">Customers</option>
 </select>

I am using the below code to pass the groups to the ajax url but ONLY one group is passed!!

<Script>
 groups=document.getElementById("groups[]").options.item(addIndex).value;
 xmlHttp.open("POST","?action=ajaxcontac&groups="+ groups,true);
</Script>

How Can I pass more than one group to the url?

Thanks

asked Jul 20, 2012 at 6:02

2 Answers 2

1
var opts = document.querySelectorAll("#groups\\[\\] option"),
 groups = [].map.call(opts, function(option) {
 if (option.selected) {
 return "groups[]=" + option.value;
 }
 }).filter(Boolean).join("&");
xmlHttp.open("POST", "?action=ajaxcontac&" + groups, true);

Demo

http://jsfiddle.net/XJLBA/1/

answered Jul 20, 2012 at 6:27
Sign up to request clarification or add additional context in comments.

Comments

1
answered Jul 20, 2012 at 6:06

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.