SEO Software
Closed Thread
Results 1 to 2 of 2

Thread: Checkboxes and arrays

  1. #1

    Default Checkboxes and arrays

    Hi all,
    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=???????????
    Thanks & regards,
    Lokananth
    Live Chat Software By miOOt


  2. SEO Software

  3. #2

    Default

    Tru out this.
    Code:
    <html>
    <script language="javascript">
    function check()
    {
    	 no = new Array();
    	i=0;
    	if(document.getElementById("1").checked)
    		no[i++]=1;
    	if(document.getElementById("2").checked)
    		no[i++]=2;
    	if(document.getElementById("3").checked)
    		no[i++]=3;
    	if(document.getElementById("4").checked)
    		no[i++]=4;
    	if(document.getElementById("5").checked)
    		no[i++]=5;
    	if(document.getElementById("6").checked)
    		no[i++]=6;
    	if(document.getElementById("7").checked)
    		no[i++]=7;
    	if(document.getElementById("8").checked)
    		no[i++]=8;
    	if(document.getElementById("9").checked)
    		no[i++]=9;
    	if(document.getElementById("10").checked)
    		no[i++]=10;
    	str = "";
    	for(j=0;j<i;j++)
    		str = str + no[j] + ";";
    	alert(str);
    }
    </script>
    
    <body>
    <input type="checkbox" name="alotofcheckboxes" value="1" id="1"/><br>
    <input type="checkbox" name="alotofcheckboxes" value="2" id="2" /><br>
    <input type="checkbox" name="alotofcheckboxes" value="3" id="3" /><br>
    <input type="checkbox" name="alotofcheckboxes" value="4" id="4" /><br>
    <input type="checkbox" name="alotofcheckboxes" value="5" id="5" /><br>
    <input type="checkbox" name="alotofcheckboxes" value="6" id="6" /><br>
    <input type="checkbox" name="alotofcheckboxes" value="7" id="7" /><br>
    <input type="checkbox" name="alotofcheckboxes" value="8" id="8" /><br>
    <input type="checkbox" name="alotofcheckboxes" value="9" id="9" /><br>
    <input type="checkbox" name="alotofcheckboxes" value="10" id="10" /><br>
    
    <br><br>
    
    <input type="button" value="Create array" onclick=check() />
    </body>
    </html>

Closed Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts