locked
CheckBox in JavaScript RRS feed

  • Question

  • User491718545 posted

    hi,

    I have 3 checkbox in Table

    <td> <input type="checkbox" "value="checked'" id="1 " /></td>

    <td> <input type="checkbox" "value="checked'" id="2 " /></td>

    <td> <input type="checkbox" "value="checked'" id="3 " /></td>

    In button click function , i want to get  selected checkBox id

    if two checkbox checked  wantto get id 1,2

    Thanks..

    Tuesday, October 29, 2013 9:40 AM

Answers

  • User551462331 posted

    use jquery

    var valChk = '';
    $("input:checked").each(function() {
      if(valChk=='')
       valChk = $(this).attr('id');
      else
       valChk = valChk + ',' + $(this).attr('id');
    })
    
    alert(valChk);

    hope this helps...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 29, 2013 9:50 AM

All replies

  • User551462331 posted

    use jquery

    var valChk = '';
    $("input:checked").each(function() {
      if(valChk=='')
       valChk = $(this).attr('id');
      else
       valChk = valChk + ',' + $(this).attr('id');
    })
    
    alert(valChk);

    hope this helps...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 29, 2013 9:50 AM
  • User491718545 posted

    its take all checkboxs id...

    i have 6 checkbox in my form..but i want to get only 3 checkboxes id which i bind in the table..

    can i take checkboxs id using checkboxname????

    <td> <input type="checkbox" name=check1" "value="checked'" id="1 " /></td>

    <td> <input type="checkbox" name=check1" "value="checked'" id="2 " /></td>

    <td> <input type="checkbox" name=check1" "value="checked'" id="3 " /></td>

    Thanks

    Tuesday, October 29, 2013 10:17 AM
  • User491718545 posted

    Thank you for ur valuable answer ..

    $('input[name=Check1:checked').each(function () {
    if (valChk == '')
    valChk = $(this).attr('id');
    else
    valChk = valChk + ',' + $(this).attr('id');
    })

    working fine..

    Thanks

    Tuesday, October 29, 2013 10:21 AM