...

View Full Version : add values in textbox if checkboxclicked



anandfred
10-30-2009, 04:38 PM
hi,i have four checkboxes and one textbox.if i checked 3 checkboxes the value 3 wil be shown in texbox.please help me,
Thanks in advance.

Philip M
10-30-2009, 05:18 PM
Here you are:-


<form name = "myform">
<input name = "myname" type = "checkbox" value = "Red" onclick="count()"> RED <br>
<input name = "myname" type = "checkbox" value = "Blue" onclick="count()"> BLUE <br>
<input name = "myname" type = "checkbox" value = "Green" onclick = "count()"> GREEN <br>
<input name = "myname" type = "checkbox" value = "Yellow" onclick = "count()"> YELLOW<br><br>
<br>
You have checked <input type = "text" size = "2" name= "totChecked" value = "0" readonly> checkboxes
</form>

<script type = "text/javascript">
function count() {
var totBoxes = 0;
for (i = 0; i < myform.myname.length; i++) {
if (myform.myname[i].checked) {
totBoxes ++;
}
}
document.myform.totChecked.value = totBoxes;
}

</script>
BTW, the time to say "thanks" is afterwards, not beforehand which gives the - doubtless unintended - impression that you take other people's voluntary unpaid assistance for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand (as you have done) and if you find a response helpful then you can use the "Thank User For This Post" button.


"How do you get your best midfielders to play together? Capello, unlike his successor, has the answer." - Football commentator



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum