Results 1 to 3 of 3

Thread: separatly treat checkbox in two different html table

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    separatly treat checkbox in two different html table

    suppose if i have two html table table1 and table2
    and each have rows with css class "case" .. each html have header with selectall checkboxes .so if i check selectall checkbox of table1 and i want to check all rows checkboxes of table1 with class css .and if second html table i.e table2 selectall checkbox select ..it should select rows of table2 with css "case"..how do this ????

    please not down that two html table with different name and header checkbox name is also different but same css of checkboxes in data rows of html table
    There is no achievement without goals

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,594

    Re: separatly treat checkbox in two different html table

    If you have 2 tables with different ID's then getting the wanted table ID will pretty much do everything you need for the specific table.
    I'm guessing a loop that checks all in checkboxes after. Not ready to give full answer and no VS here but a for each element in tableX , if elements is checkbox then, if not checked then check.
    I think would be a basic task if you google it.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3
    Member
    Join Date
    Jul 2019
    Location
    Ahmedabad
    Posts
    57

    Re: separatly treat checkbox in two different html table

    Hello,@ERUM
    Please try this code, To separatly treat checkbox in two different html table
    Code:
    $('#select_all1').bind('click', function() {
      var checkedState = this.checked;
      $('#table1 :checkbox').each(function() {
          this.checked = checkedState;
      });
    });
    
    $('#select_all2').bind('click', function() {
      var checkedState = this.checked;
      $('#table2 :checkbox').each(function() {
          this.checked = checkedState;
      });
    });
    Code:
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <input type="checkbox" id="select_all1"></input>
    <table id="table1">
      <tr>
        <td>
          <input type="checkbox" />
        </td>
        <td>
          <input type="checkbox" />
        </td>
        <td>
          <input type="checkbox" />
        </td>
      </tr>
      <tr>
        <td>
          <input type="checkbox" />
        </td>
        <td>
          <input type="checkbox" />
        </td>
        <td>
          <input type="checkbox" />
        </td>
      </tr>
    </table>
    
    <input type="checkbox" id="select_all2"></input>
    <table id="table2">
      <tr>
        <td>
          <input type="checkbox" />
        </td>
        <td>
          <input type="checkbox" />
        </td>
        <td>
          <input type="checkbox" />
        </td>
      </tr>
      <tr>
        <td>
          <input type="checkbox" />
        </td>
        <td>
          <input type="checkbox" />
        </td>
        <td>
          <input type="checkbox" />
        </td>
      </tr>
    </table>
    I hope this code will be useful to you.
    Thank you.
    < advertising removed by moderator >

Posting Permissions

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



Click Here to Expand Forum to Full Width