0

I have a table structure like this..

<form name="kuchbhi">
    <table id="x">
        <tr name="alpha"> 
            <td><input name="a" type="checkbox"></td>
            <td><input name="b" type="checkbox"></td>
        </tr>
        <tr name="beta"> 
            <td><input name="a" type="checkbox"></td>
            <td><input name="b" type="checkbox"></td>
        </tr>
    </table>
    <table id="y">
        <tr name="alpha"> 
            <td><input name="a" type="checkbox"></td>
            <td><input name="b" type="checkbox"></td>
        </tr>
        <tr name="beta">
            <td><input name="a" type="checkbox"></td>
            <td><input name="b" type="checkbox"></td> <!--This one-->
        </tr>
    </table>
</form>

Now, I have only 2 info (tr name) and (input name). For example I have (beta, a). Now I want to put a check on that checkbox (on the second table named y). How to select that checkbox?

awwwd
  • 121
  • 2
  • 9
  • $('#y tr[name='beta'] input[name='a']").attr('checked','checked') will be the thing that you want – Siamand Apr 30 '17 at 19:52
  • Possible duplicate of [What's the proper value for a checked attribute of an HTML checkbox?](http://stackoverflow.com/questions/7851868/whats-the-proper-value-for-a-checked-attribute-of-an-html-checkbox) – Andrea Carraro Apr 30 '17 at 19:53

2 Answers2

1

try this:

var trname = 'beta';
var inname = 'a';

$( 'tr[name="' + trname + '"] input[name="' + inname + '"]' ).attr( 'checked', 'checked' );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form name="kuchbhi">
    <table id="x">
        <tr name="alpha"> 
            <td><input name="a" type="checkbox"></td>
            <td><input name="b" type="checkbox"></td>
        </tr>
        <tr name="beta"> 
            <td><input name="a" type="checkbox"></td>
            <td><input name="b" type="checkbox"></td>
        </tr>
    </table>
    <table id="y">
        <tr name="alpha"> 
            <td><input name="a" type="checkbox"></td>
            <td><input name="b" type="checkbox"></td>
        </tr>
        <tr name="beta">
            <td><input name="a" type="checkbox"></td>
            <td><input name="b" type="checkbox"></td> <!--This one-->
        </tr>
    </table>
</form>
Kresimir Pendic
  • 3,597
  • 1
  • 21
  • 28
0

Using jquery, do it like this:

$('#y tr[name=beta] td>input[name=b]')
gaganshera
  • 2,629
  • 1
  • 14
  • 21