Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Old 08-04-2009, 03:54 AM   #1 (permalink)
Junior Member
 
Join Date: 06-29-09
Posts: 19
iTrader: 0 / 0%
Latest Blog:
None

gilbertsavier in the red
Checkboxes and arrays

Hello,
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
<a href="http://www.mioot.com">Live Chat Software</a> By miOOt
gilbertsavier is offline  
Add Post to del.icio.us
Reply With Quote
Old 08-04-2009, 08:15 AM   #2 (permalink)
v7n Mentor
 
Izzmo's Avatar
 
Join Date: 11-01-03
Location: Kansas City
Posts: 1,338
iTrader: 0 / 0%
Latest Blog:
Starting p90x today

Izzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web pro
Send a message via ICQ to Izzmo Send a message via AIM to Izzmo Send a message via MSN to Izzmo Send a message via Yahoo to Izzmo
Well, first things first.. you can't have a bunch of checkbox inputs with the same name, that will not work. They each need to have their own unique name/id.

Also, if you want to add more checkboxes dynamically, you will need to keep an active count of the number of checkboxes present on the page, if not, you can just do a for loop for say checkbox input 0-9 (1-10).

Static would be:

Code:
function getArray() { var arr = new array(); for(i = 1; i <= 10; i++) { var cb = document.getElementById("cb"+i); if(cb.checked) arr[] = cb.value; } }
Code:
<input type="checkbox" id="cb1" value="1" /> <input type="checkbox" id="cb2" value="2" /> <input type="checkbox" id="cb3" value="3" /> <input type="checkbox" id="cb4" value="4" /> <input type="checkbox" id="cb5" value="5" /> <input type="checkbox" id="cb6" value="6" /> <input type="checkbox" id="cb7" value="7" /> <input type="checkbox" id="cb8" value="8" /> <input type="checkbox" id="cb9" value="9" /> <input type="checkbox" id="cb10" value="10" /> <input type="button" value="Create array" onclick="javascript:getArray()" />
Note: I did not put in the name attribute.. so if you want this form to submit, you will need that for the POST/GET values.
__________________
Izzmo
Coding Guru Extraordinaire
ZeroWeb Hosting & Design - Customizable hosting for every type of user!
Izzmo is offline  
Add Post to del.icio.us
Reply With Quote
Old 08-06-2009, 07:09 AM   #3 (permalink)
Contributing Member
 
olddocks's Avatar
 
Join Date: 04-03-06
Location: hrwebdir.org
Posts: 119
iTrader: 0 / 0%
olddocks is just really niceolddocks is just really niceolddocks is just really niceolddocks is just really niceolddocks is just really niceolddocks is just really niceolddocks is just really niceolddocks is just really nice
check this out: http://corpocrat.com/2009/05/24/how-...ysql-with-php/

There cant be a better easy tutorial than this.
olddocks is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Appending to MultiDimensional Arrays bytech Coding Forum 5 03-03-2007 07:06 PM
problem with PHP and arrays I think Arenlor Coding Forum 4 01-19-2007 11:35 AM
hiding checkboxes with JS I like pie Coding Forum 5 11-17-2006 06:45 PM
PHP - Using assoc. arrays in SQL string trevHCS Coding Forum 1 09-24-2004 03:49 AM


Sponsor Links
Get exposure! Contextual Links V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 01:46 AM.
© Copyright 2008 V7 Inc
Powered by vBulletin
Copyright Đ 2000-2009 Jelsoft Enterprises Limited.


Search Engine Optimization by vBSEO 3.3.0 ©2009, Crawlability, Inc.