Go4Expert

Go4Expert (http://www.go4expert.com/)
-   JavaScript and AJAX (http://www.go4expert.com/forums/javascript/)
-   -   Checkboxes and arrays (http://www.go4expert.com/forums/checkboxes-and-arrays-t18828/)

gilbertsavier 5Aug2009 15:24

Checkboxes and arrays
 
Hi,
I need some code which can give an array some values, depending on which checkboxes which is selected.
I think I will give these checkboxes (lets say 10 checkboxes) some values, and when you have selected the relevant checkboxes, you will have to click a button: "Create array". Then a array is created, and it will have the same number of values as there are checkboxes selected. And the values in the array will be the values of the selected checkboxes.

If I, for instance, select checkbox number 1, 4 and 7, and I click "Create array", the content of the array will be: 1,4,7

What will the code be for that. I donīt have the javascript code, only the HTML:

HTML Code:

<input type="checkbox" name="alotofcheckboxes" value="1" />
<input type="checkbox" name="alotofcheckboxes" value="2" />
<input type="checkbox" name="alotofcheckboxes" value="3" />
<input type="checkbox" name="alotofcheckboxes" value="4" />
<input type="checkbox" name="alotofcheckboxes" value="5" />
<input type="checkbox" name="alotofcheckboxes" value="6" />
<input type="checkbox" name="alotofcheckboxes" value="7" />
<input type="checkbox" name="alotofcheckboxes" value="8" />
<input type="checkbox" name="alotofcheckboxes" value="9" />
<input type="checkbox" name="alotofcheckboxes" value="10" />

<br><br>

<input type="button" value="Create array" onclick=???????????

pradeep 10Aug2009 10:45

Re: Checkboxes and arrays
 
HTML Code:

<input type="checkbox" name="alotofcheckboxes[]" value="1" />
<input type="checkbox" name="alotofcheckboxes[]" value="2" />
<input type="checkbox" name="alotofcheckboxes[]" value="3" />
<input type="checkbox" name="alotofcheckboxes[]" value="4" />
<input type="checkbox" name="alotofcheckboxes[]" value="5" />
<input type="checkbox" name="alotofcheckboxes[]" value="6" />
<input type="checkbox" name="alotofcheckboxes[]" value="7" />
<input type="checkbox" name="alotofcheckboxes[]" value="8" />
<input type="checkbox" name="alotofcheckboxes[]" value="9" />
<input type="checkbox" name="alotofcheckboxes[]" value="10" />

<br><br>

You'll get the checked ones as an array.


All times are GMT +5.5. The time now is 04:18.