/    Sign up×
Community /Pin to ProfileBookmark

how to Select all checkbox moves values to text area

Ok I have a list of check boxes. when a box is selected the value gets put into a text area. I aslso have a button to select all or deselect all check boxes. However I can’t get all the values from the checkboxes into the textarea when the “select all” button is clicked. any help would be greatly appreciated. here is what I have below:

<SCRIPT LANGUAGE=”JavaScript”>
function Doit()
{
myval=””
re=/,$/ // Use regular expression to remove comma from last value added to text box
for(i=0;i<myform.ckb.length;i++)
{
if(myform.ckb[i].checked)
{myval+=myform.ckb[i].value+”,”}
}
myform.txt1.value=myval.replace(re,””)
}

function setParentValue() {
//if (this.document.myform.txt1.value != null &&
//this.document.myform.txt1.value != “”) {
window.opener.document.forms[0].myTextBox.value +=
this.document.myform.txt1.value;
this.close();
//}
}

function checkAll(field)
{
var obj=document.all.ckb
for (i = 0; i < obj.length; i++)
obj.ckb[i].checked = true ;
}

function uncheckAll(field)

{
var obj=document.all.ckb
for (i = 0; i < obj.length; i++)
obj.ckb[i].checked = false ;
}

</script>

<body>
<FORM NAME=”myform”>

<input type=”checkbox” name=”ckb” value=”[email protected]” onClick=”Doit(this.form)”>Eddie Vedder<br>
<input type=”checkbox” name=”ckb” value=”[email protected]” onClick=”Doit(this.form)”>George Bush<br>
<input type=”checkbox” name=”ckb” value=”[email protected]” onClick=”Doit(this.form)”>Stone Gossard<br>
<input type=”checkbox” name=”ckb” value=”[email protected]” onClick=”Doit(this.form)”>Michael Jordan<br>

<textarea name=”txt1″ cols=”35″ rows=”15″></textarea><br>
<a href=”javascript:checkAll(document.myform.ckb)”>select all</a><br>
<a href=”javascript:uncheckAll(document.myform.ckb)”>remove all</a>
</body>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@steelersfan88Apr 13.2004 — Why not replace:&lt;a href="java script:checkAll(document.myform.ckb)"&gt;select all&lt;/a&gt;&lt;br&gt;
&lt;a href="java script:uncheckAll(document.myform.ckb)"&gt;remove all&lt;/a&gt;
with&lt;a href="#" onclick="checkAll(document.myform.ckb);Doit(this.form);return false;"&gt;select all&lt;/a&gt;&lt;br&gt;
&lt;a href="#" onclick="uncheckAll(document.myform.ckb);Doit(this.form);return false;"&gt;remove all&lt;/a&gt;
×

Success!

Help @glamias 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...