How to make checkbox array?

Sometimes while designing any form, we required to give multiple options to user. At that time our mind immediately say, put checkboxes and give multiple selections to user.

But while working with any server side scripting, our form and all its controls are submitted. So we must have to give proper name to each control.

Now if we are using multiple checkboxes to get multiple selections of same type of data, then it is difficult to give different names to each and every checkbox control.

At that time we can make group of checkboxes as a checkbox array, where all the checkboxes are related.

In which we just required to give common name to each checkbox with rectangular brackets [].

So now each checkbox is an element of checkbox array.

For example: Here we are making checkbox array to select multiple colors.

<input type="checkbox" name="colors[]" value="Red" /> Red

<input type="checkbox" name="colors[]" value="Green" /> Green

<input type="checkbox" name="colors[]" value="Blue" /> Blue

Hope this will help you.

Speak Your Mind

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: