Multi select box, post all values

Hello I have a multi-select box. And when I select multiple options, I would be able to post all the selected options. I can do that in the HTML way. But I am unaware of the method using javascript to dynamically build a multiple select box and post all the selected options.

Attached in the code has two parts, one would show how to post all selected values, and the other part would show where I am stuck right now.

In part one, I have the name of my multi select box as an array, so on submit, all selected values are posted. In part two,  I am creating a multi select box dynamically, and if I try to add the name as an array, I get a syntax error point towards the square brackets. Do we have a way around for this problem??
part one:

<form method="post" action="">
    <select name=components[] multiple size=5>
      <option value=1>1</option>
      <option value=2>2</option>
      <option value=3>3</option>
      <option value=4>4</option>
      <option value=5>5</option>
<input type="submit" name="submit" value="us" />

part two:

newSelectorElm = document.createElement('select'); = wName; = wName;
// = wName[];
newSelectorElm.multiple = true;

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

<html xmlns="">
<script language="JavaScript" type="text/javascript">

function makeSelect(wName,opts,target)
	var newSelectorElm = document.createElement('select'); = wName; = wName;
	newSelectorElm.multiple ="multiple";

	for( var i in opts)
		newSelectorElm.options[newSelectorElm.options.length]=new Option(opts[i],i);

	var opts=['baseball','basquetball','football'];


		<div id='targetDiv'></div>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gautam_reddycAuthor Commented:
Thanks! got my solution!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.