views:

78

answers:

3
<script type="text/javascript">
$(document).ready(function() {
    $("#paradigm_all").click(function() {
        var checked_status = this.checked;
        $("input[@name=paradigm]").each(function() {
            this.checked = checked_status;
        });
    });
});

</script>


<table class="data-table">
    <tr>
         <th>
            Redni br.
        </th>
        <th>
            Br. Indexa
        </th>
        <th>
            Prezime
        </th>
        <th>
            Ime
        </th>
        <th>
           <input id="paradigm_all" type="checkbox" />
        </th>  
    </tr>       
<% int rb = 1;%>
<% foreach (var item in Model)
   { %>       
    <tr>
    <td>
            <input readonly="readonly" class="input-box" id="rb" type="text" name="rb"  value="<%= Html.Encode(rb)%>" />
        </td>            
        <td>

            <input readonly="readonly" class="input-box" id="id_stud" type="text" name="id_stud"  value="<%= Html.Encode(item.id_stud)%>" />

        </td>
        <td>
            <%= Html.Encode(item.prezime)%>
        </td>
        <td>
             <%= Html.Encode(item.ime)%>
        </td>
         <td>
           <input  name="paradigm" type="checkbox" /> 
        </td>
    </tr>

<% rb = rb + 1;%>
<% } %>

</table>

Why this java script does not work? Pls help

+1  A: 
   $("input[@name=paradigm]").attr('checked',checked_status);

The reason yours doesn't worked is because $('...').checked is a value return, not a reference. To change the checked attribute, you need to use the attr setter.

Stefan Kendall
I do not understand where to put this code
Ognjen
$(document).ready(function() { $("#paradigm_all").click(function() { $('input[name=paradigm]').attr('checked', true); }); });did you mean this
Ognjen
`@` has been deprecated in jQuery, use `$("input[name=paradigm")`...
fudgey
Do you know what version of jQuery he's using? Not everyone can use latest for various reasons. I used what he had.
Stefan Kendall
jquery-1.3.2.min.js
Ognjen
A: 

Woah dude, you have some crazy things going on here, I suggest cleaning up the way it was pasted here, I think we could read it better then.

Joseph Silvashy
A: 

I think you can safely remove the each from this code

$(document).ready(function() {
   $("#paradigm_all").click(function() {
    $("input[name=paradigm]").attr({checked: $(this).is(':checked')});
  });
czarchaic
code is correct, but no @ in front of name:$("input[name=paradigm]").attr({checked: $(this).is(':checked')});Problem is solved.Thanks!!!
Ognjen