Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    add values in textbox if checkboxclicked

    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.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Here you are:-

    Code:
    <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
    Last edited by Philip M; 10-30-2009 at 06:43 PM.

  • Users who have thanked Philip M for this post:

    anandfred (10-31-2009)


  •  

    Posting Permissions

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