/    Sign up×
Community /Pin to ProfileBookmark

Create javascript array using checkboxes

Hi, I want to create an array of the values of the boxes that are clicked:

[code=html]<form>
<input type=”checkbox” name =”drink1″ value=”beer” id=”drink1″/>
<label for=”beer”>Beer</label>

<input type=”checkbox” name =”drink2″ value=”cider” id=”drink2″/>
<label for=”cider”>Cider</label>

<input type=”checkbox” name =”drink3″ value=”wine” id=”drink3″/>
<label for=”wine”>Wine</label>

<input type=”checkbox” name =”drink4″ value=”spirits” id=”drink4″/>
<label for=”spirits”>Spirits</label>

<input type=”checkbox” name =”drink5″ value=”alcopop” id=”drink5″/>
<label for=”alcopop”>Alcopop</label>

<input type=”checkbox” name =”drink6″ value=”other” id=”drink6″/>
<label for=”other”>Other</label>
</div>

<a href=”#Q4″><input type=”submit” name=”” value=”Submit” data-theme=”e”/></a>
</form>[/code]

all help is greatly appreciated. thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsAug 31.2011 — [CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script type="text/javascript">
/*<![CDATA[*/

function Total(frm,nme){
var els=frm.elements,ary=[],z0=0;
for (;z0<els.length;z0++){
if (els[z0].name&&els[z0].name.replace(/d/g,'')==nme&&els[z0].checked){
ary.push(els[z0].value);
}
}
alert(ary.join('n'));
}
/*]]>*/
</script></head>

<body>
<form>
<input type="checkbox" name ="drink1" value="beer" id="drink1"/>
<label for="beer">Beer</label>

<input type="checkbox" name ="drink2" value="cider" id="drink2"/>
<label for="cider">Cider</label>

<input type="checkbox" name ="drink3" value="wine" id="drink3"/>
<label for="wine">Wine</label>

<input type="checkbox" name ="drink4" value="spirits" id="drink4"/>
<label for="spirits">Spirits</label>

<input type="checkbox" name ="drink5" value="alcopop" id="drink5"/>
<label for="alcopop">Alcopop</label>

<input type="checkbox" name ="drink6" value="other" id="drink6"/>
<label for="other">Other</label>
</div>
<input type="button" name="" value="Test" onmouseup="Total(this.form,'drink');"/>
<a href="#Q4"><input type="submit" name="" value="Submit" data-theme="e"/></a>
</form>
</body>

</html>[/CODE]
Copy linkTweet thisAlerts:
@sjjs1985authorAug 31.2011 — thank you so much

sjjs1985 loves you and will never love you less ?
Copy linkTweet thisAlerts:
@sjjs1985authorSep 02.2011 — Hi. How could I get this array into a GA tracker?

[code=html]onclick="_gaq.push(['_trackEvent', 'Drinks', 'ARRAY-OF-DRINKS']);"[/code]

Thanks in advance

SJ
×

Success!

Help @sjjs1985 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...