单选按钮 - 从Db读取预选值

I have a radio button which reads the value from mysql and highlights the correct radio button successfully. I also have jquery validation which when the radio button is at 'no' value the 2 dropdown menus are greyed out.

My problem lies in that when a user selects 'no' radio button it saves it to mysql but when he/she logs back in the radio button is at correctly at 'no' position however the 2 drop down menus are NOT greyed out as they should be. If i then click on the 'no' radio button they grey out.

I obviously do not want this, if a user selected 'no' then logs back in i want the dropdown menus to be greyed out on login.

php code:

<?php
$row2 = "SELECT * FROM user WHERE username = '" . mysql_real_escape_string($_SESSION['username']) . "'";
$result = mysql_query($row2) or die("Error in SQL: " . mysql_error());
$row3 = mysql_fetch_array($result);

?>

RADIO BUTTON CODE:

       <input name="attendance1" type="radio" id="Yes" value="Yes" <?php if($row3['attendance1']=="Yes") { echo "checked"; }?>/>Yes 
                 <br />
         <input name="attendance1" type="radio" id="No" value="No" <?php if($row3['attendance1']=="No") { echo "checked"; }?>/>No

I would be greatful if someone could tell me where i am going wrong. When retrieving the value from the database it is obviously not physically selecting the radio button which i would like it to do

JQUERY VALIDATION:

          <script src="jquery.js"></script>
         <script>      
            $( function(){    
                    function validate(id){       
                        var enabled = ($("input[name='attendance" + id + "']:checked").val() == 'Yes');         
                        if(enabled){              
                            //Please select option is selected              
                            if($("#colour" + id)[0].selectedIndex == 0){                 
                            alert('Please make your colour selection');                  
                            return false;             
                            }              
                            //Please select option is selected              
                            if($("#shade" + id)[0].selectedIndex == 0){                  
                                alert('Please select your shade');                  
                                return false;             
                            } 


                        }     
                        return true;    
                    };

                    $("input[name^='attendance']").click(function() {  

                        var id = this.name.replace('attendance', '');      
                        $("#colour" + id + ", #shade" + id).prop("disabled", this.value == 'No');         
                        validate(id);    
                    });      
                   $("input:submit").click(function(){         
                       var retVal = true;
                       $.each([1], function(i, val){
                          retVal = (validate(val) && retVal);
                       });
                        return retVal;   

$(document).ready(function(){    

$("input[name=attendance1]:checked").triggerHandler('click'); 
});     
</script>

two dropdowns are called colour and shade

Have jQuery trigger the onclick handler when the page loads:

$(document).ready(function(){
   $("input[name=attendance]:checked").triggerHandler('click');
});

So your total code would look something like:

<script src="jquery.js"></script>
<script>      
$( function(){    
    function validate(id){       
        var enabled = ($("input[name='attendance" + id + "']:checked").val() == 'Yes');         
        if(enabled){              
            //Please select option is selected              
            if($("#colour" + id)[0].selectedIndex == 0){                 
            alert('Please make your colour selection');                  
            return false;             
            }              
            //Please select option is selected              
            if($("#shade" + id)[0].selectedIndex == 0){                  
                alert('Please select your shade');                  
                return false;             
            } 


        }     
        return true;    
    };

    $("input[name^='attendance']").click(function() {  

        var id = this.name.replace('attendance', '');      
        $("#colour" + id + ", #shade" + id).prop("disabled", this.value == 'No');         
        validate(id);    
    });      
   $("input:submit").click(function(){         
       var retVal = true;
       $.each([1], function(i, val){
          retVal = (validate(val) && retVal);
       });
        return retVal;  
   });
});

$(document).ready(function(){    
    $("input[name=attendance]:checked").triggerHandler('click'); 
});     

</script>

You need to add something along the lines of this in your head so it is automatically disabled when the page loads. I'm sure you can figure out an appropriate value for id.

<script>
$(document).ready(function () {
  $("#colour" + id + ", #shade" + id).prop("disabled", this.value == 'No');
});
</script>

You could disable the drop downs from the PHP, but this is a bad idea because you will screw over people with JavaScript disabled.