0

I am assigned to get the boolean value of a checkbox.

I couldn't find a way to get the boolean value of the checkbox. e.g: true,false.

Is there a way to do this?

Link: https://jsfiddle.net/hongyang1033/ek30dgt9/5/

    <body>

    <div >

    <table border=1px>

  <thead>
    <tr>
        <th colspan="5">Description</th>
        <th>Comment</th>
        <th>User</th>
        <th>Feedback</th>
        <th>Status</th>
    </tr>
    </thead>
        <tbody style="border-top : 1px solid black" id = "1">
    <tr>
        <td class="partition"><label class="label">Title:</label><label class="label ">A</label></td>
        <td class="sip" style="border-left:none"><label class="label">Author:</label><label class="label">James</label></td>
        <td rowspan="4"><input type="checkbox"><label class="label" style="padding-left:0px" id="bookstore">BookStore</label></td>
        <td rowspan="4"><input type="checkbox"><label class="label" style="padding-left:0px" id="ebook">Ebook</label></td>
        <td rowspan="4"><input type="checkbox"><label class="label" style="padding-left:0px" id="library">Library</label></td>
        <td rowspan="4"><textarea maxlength="180" class="animated" id="usercomment" name="comment" style="overflow: hidden; word-wrap: break-word; resize: horizontal;  height: 80px; width:280px;">The book is ..........</textarea></td>
        <td rowspan="4" align="center">Adam<br><button class="label label-primary" id="submit">Submit</button></td>
        <td rowspan="4" align="center">Feedback Goes Here<br></td>
            <td rowspan="4" align="center"><br>No Feedback Yet</td>
    </tr>
    <tr>
        <td colspan="2" class="def"><label class="label">Genre:</label><label class="label">Fiction</label></td>
    </tr>
    <tr>
        <td colspan="2" class="path"><label class="label label-primary" style="margin-left:5px">BookURL</label><label class="label label-primary " style="margin-left:40px">DownloadLink</label></td>
    </tr>
    <tr>
        <td colspan="2" class="path"><a style="display:none">www.ddd.com/bookurl</a></td>
    </tr>
</tbody>

JQuery

$("#submit").click(function() {
var $row = $(this).closest("tbody");   
var $text = $row.document.getElementById("#emulation").checked(); // 
alert($text);
});
Xpx
  • 137
  • 1
  • 2
  • 7
  • 3
    possible duplicate of [Get checkbox value in jQuery](http://stackoverflow.com/questions/2834350/get-checkbox-value-in-jquery) – Juan Jul 28 '15 at 18:18
  • 1
    Possible duplicate of [this](http://stackoverflow.com/questions/2204250/check-if-checkbox-is-checked-with-jquery?rq=1), [this](http://stackoverflow.com/questions/2834350/get-checkbox-value-in-jquery?rq=1) and [this](http://stackoverflow.com/questions/4813219/testing-if-a-checkbox-is-checked-with-jquery?rq=1) to name a few. – cloudworks Jul 28 '15 at 18:29
  • 1
    possible duplicate of [Check checkbox checked property](http://stackoverflow.com/questions/901712/check-checkbox-checked-property) – cloudworks Jul 28 '15 at 18:33

1 Answers1

1

As id is unique, hence, you can get it directly. Use, is() function to check the property.

Update from

var $text = $row.document.getElementById("#emulation").checked();

to

var $text = $("#emulation").is(":checked"); 
Nikhil Aggarwal
  • 28,197
  • 4
  • 43
  • 59