user3589097
user3589097

Reputation:

jQuery checkboxes error

I am making a form validation and I set the property of other checkboxes disable if the owner checkbox is not checked but it is not working.
Here's my html cod:

<!DOCTYPE html>
<html>
<head>
    <title>jQuery</title>

    <script src="script.js"></script>
    <script src="min.js"></script>

</head>
<body>

Owner:<input type="checkbox" id="owner">
<hr>
<div id="check">
bicycle:<input type="checkbox" id="bicycle"><br>
bike:<input type="checkbox" id="bike"><br>
car:<input type="checkbox" id="car">
</div>

<script>


</script>


</body>
</html>

and in it min.js is jQuery installation file and ,
here is script.js :

$(document).ready(function(){

        var $checkbox = $("#check").find("input[type=checkbox]");
        $checkbox.prop('disabled', true);

        $("#owner").click(function(){
            var $ownercheck = $(this);

        if ($ownercheck.prop('checked') === true) {
                $checkbox.prop('disabled', false);
        }
        else
        {
            $checkbox.prop('disabled', true);
        }

    });

});

Upvotes: 2

Views: 80

Answers (2)

Mirza Muneeb
Mirza Muneeb

Reputation: 136

You have to put min.js above the script.js,
and your html code will look like this :

<!DOCTYPE html>
<html>
<head>
    <title>jQuery</title>

    <script src="min.js"></script>
    <script src="script.js"></script>

</head>
<body>

Owner:<input type="checkbox" id="owner">
<hr>
<div id="check">
bicycle:<input type="checkbox" id="bicycle"><br>
bike:<input type="checkbox" id="bike"><br>
car:<input type="checkbox" id="car">
</div>

</body>
</html>

Upvotes: 4

martynas
martynas

Reputation: 12300

You must always load the library first. For issue to be fixed, script.js must go after min.js. Your code is working perfectly fine: http://jsfiddle.net/zb3m3/1/

<script src="min.js"></script>    
<script src="script.js"></script>

Upvotes: 2

Related Questions