Wednesday, January 8, 2014

html disable select option in jquery

<body>
<div>
    <select id="org_type">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
    </select>

    <select id="place">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
    </select>

    <select id="area">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
    </select>
</div>

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
   $(document).ready(function(){

       // open
       var open ={};
       //          org_type, place, area
       open['9'] = [true, true, true];
       open['0'] = [false, false, false];
       open['1'] = [false, true, false];
       open['3'] = [true, true, false];

       $('#org_type').val(5);
       $('#place').val(2);
       $('#area').val(1);

       checkAuth(open['3']);
   });

    function checkAuth(auth){
        $("#org_type").attr("disabled", !auth[0]);
        $("#place").attr("disabled", !auth[1]);
        $("#area").attr("disabled", !auth[2]);
    }

</script>

No comments:

Post a Comment