-1

Here's the code I'm working on:

$(document).ready(function(){
    var rewrite= function() {
        $("#numback_**SQL_Value**").attr("readonly" , "readonly");
        $("#numback_**SQL_Value**").attr("value" ,function() { return ($(".Report_Box").size() +**SQL_Value**;)}
    )};
    $(".Report_Box").click(rewrite);
});

Report_Box is a class of checkboxes later in the code. When one of the checkboxes is changed, the rewrite function is supposed to trigger.

Rewrite is supposed to lock the numback input box, turning it read only as I set the value to the number of Report_Box'es clicked.

  • Have you checked the error console (F12)? Have you tried removing the `*` characters from the `id` of the elements you're trying to select, because I'm relatively certain they're not valid characters. – David Thomas Dec 08 '15 at 22:51

2 Answers2

0

I simplified your code to this - and it worked ok. I added the code you can use to make the input readonly... See the description of using prop not attr here: Setting a control to readonly using jquery 1.6 .prop()

<div>
<input type="checkbox" class="Report_Box"/>
<input type="checkbox" class="Report_Box"/>
<input type="checkbox" class="Report_Box"/>
<input type="checkbox" class="Report_Box"/>
<input type="checkbox" class="Report_Box"/>

<input type="text" id="makero"/>

<script>
$(document).ready(function(){

    var rewrite= function() {
        $('#makero').val($(".Report_Box").size()).prop('readonly', true);
            console.log($(".Report_Box").size());
        };
    $(".Report_Box").click(rewrite);
});

Community
  • 1
  • 1
nril
  • 558
  • 2
  • 7
0

Could it be the typos that is causing your trouble? Try this:

$("#numback_**SQL_Value**").attr("value", function() { return($(".Report_Box").size()+"**SQL_Value**");} )};