0

HTML Table's:

/* one table */
    <table class="table borderless" id="cegadatok">
        <tr class="info">
            <td width="5%"><input type="checkbox" class="checkAll" value="89"></td>
            <td width="25%">Company name</td>
            <td width="20%">Email address</td>
            <td width="35%">Address </td>
            <td width="15%">Tax numver</td>
        </tr>
    </table>
    <table class="table borderless" id="tetelek" style="width: 90%;" align="right">
        <tr>
            <td width="5%"><input type="checkbox" value="1"></td>
            <td class="warning">1</td>
            <td class="warning">2</td>
            <td class="warning">3</td>
        </tr>
        <tr>
            <td width="5%"><input type="checkbox" value="2"></td>
            <td class="warning">4</td>
            <td class="warning">5</td>
            <td class="warning">6</td>
        </tr>
        <tr>
            <td width="5%"><input type="checkbox" value="3"></td>
            <td class="warning">7</td>
            <td class="warning">8</td>
            <td class="warning">9</td>
        </tr>

    </table>

    /* Two table */
    <table class="table borderless" id="cegadatok">
        <tr class="info">
            <td width="5%"><input type="checkbox" class="checkAll" value="90"></td>
            <td width="25%">Company name</td>
            <td width="20%">Email address</td>
            <td width="35%">Address </td>
            <td width="15%">Tax numver</td>
        </tr>
    </table>
    <table class="table borderless" id="tetelek" style="width: 90%;" align="right">
        <tr>
            <td width="5%"><input type="checkbox" value="1"></td>
            <td class="warning">1</td>
            <td class="warning">2</td>
            <td class="warning">3</td>
        </tr>
        <tr>
            <td width="5%"><input type="checkbox" value="2"></td>
            <td class="warning">4</td>
            <td class="warning">5</td>
            <td class="warning">6</td>
        </tr>
        <tr>
            <td width="5%"><input type="checkbox" value="3"></td>
            <td class="warning">7</td>
            <td class="warning">8</td>
            <td class="warning">9</td>
        </tr>

    </table>
    /* Etc tables ... */

jQuery code:

    $( document ).ready(function() {

        $(".checkAll").click(function(e){
            $(this).closest('tr').attr('class', 'success');
            if(!this.checked){
                $(this).closest('tr').attr('class', 'info');
            }
            $('#tetelek').find('td input:checkbox').prop('checked', this.checked);
            $('#tetelek').find('td').prop('class', 'success');
        });


    });

I would like to create a sample invoice generator systems. If I click to checkbox id's 'checkAll', the jquery put 'selected' checkbox in id="tetelek" table. And over the click, I would like to set td class: active (from bootstrap). So, example.

Thank you!

2 Answers 2

0

The only thing you're missing is the last line should be:

 $('#tetelek').find('td').toggleClass('active',this.checked);

$(".checkAll").click(function(e){
  $(this).closest('tr').attr('class', 'success');
  if(!this.checked){
    $(this).closest('tr').attr('class', 'info');
  }
  $('#tetelek').find('td input:checkbox').prop('checked', this.checked);
  $('#tetelek').find('td').toggleClass('active',this.checked);
});
td.active{
  background:green
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table borderless" id="cegadatok">
        <tr class="info">
            <td width="5%"><input type="checkbox" class="checkAll" value="89"></td>
            <td width="25%">Company name</td>
            <td width="20%">Email address</td>
            <td width="35%">Address </td>
            <td width="15%">Tax numver</td>
        </tr>
    </table>
    <table class="table borderless" id="tetelek" style="width: 90%;" align="right">
        <tr>
            <td width="5%"><input type="checkbox" value="1"></td>
            <td class="warning">1</td>
            <td class="warning">2</td>
            <td class="warning">3</td>
        </tr>
        <tr>
            <td width="5%"><input type="checkbox" value="2"></td>
            <td class="warning">4</td>
            <td class="warning">5</td>
            <td class="warning">6</td>
        </tr>
        <tr>
            <td width="5%"><input type="checkbox" value="3"></td>
            <td class="warning">7</td>
            <td class="warning">8</td>
            <td class="warning">9</td>
        </tr>

    </table>

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, Jamiec! Code works well! How edit jQuery code, if I would like more tables, example: more than 100... ? Thanks!
0
<table class="table table-hover" >
    <tr class="active">
        <td width="5%"><input type="checkbox" class="checkAll" value="89"></td>
        <td width="25%">Company name 1</td>
        <td width="20%">Email address 1</td>
        <td width="35%">Address 1</td>
        <td width="15%">Tax numver 1</td>
    </tr>
    <tr>
        <td></td>
        <td class="active" width="5%"><input type="checkbox" value="1"></td>
        <td class="active">1</td>
        <td class="active">2</td>
        <td class="active">3</td>
    </tr>
    <tr>
        <td></td>
        <td class="active" width="5%"><input type="checkbox" value="2"></td>
        <td class="active">4</td>
        <td class="active">5</td>
        <td class="active">6</td>
    </tr>
    <tr>
        <td></td>
        <td class="active" width="5%"><input type="checkbox" value="3"></td>
        <td class="active">7</td>
        <td class="active">8</td>
        <td class="active">9</td>
    </tr>
    <tr class="active">
        <td width="5%"><input type="checkbox" class="checkAll" value="89"></td>
        <td width="25%">Company name 2</td>
        <td width="20%">Email address 2</td>
        <td width="35%">Address 2</td>
        <td width="15%">Tax numver 2</td>
    </tr>
    <tr>
        <td></td>
        <td class="active" width="5%"><input type="checkbox" value="1"></td>
        <td class="active">1</td>
        <td class="active">2</td>
        <td class="active">3</td>
    </tr>
    <tr>
        <td></td>
        <td class="active" width="5%"><input type="checkbox" value="2"></td>
        <td class="active">4</td>
        <td class="active">5</td>
        <td class="active">6</td>
    </tr>
    <tr>
        <td></td>
        <td class="active" width="5%"><input type="checkbox" value="3"></td>
        <td class="active">7</td>
        <td class="active">8</td>
        <td class="active">9</td>
    </tr>
</table>

During, I need modify tables structure. The essential the first version. When I click the company tr, it's under checkbox will ckeck. Thanks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.