Michael Angelo Jopia Michael Angelo Jopia - 7 months ago 30
HTML Question

Dropdown not disable when radio button is clicked

It's supposed to be working but unfortunately it isn't. I don't know what is wrong with my code. When I try in jsfiddle , it's working but in my Notepad++ it doesn't works. I can't figure out what's wrong with this.

<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript">

$('input:radio[name="senior"]').change(function() {
if ($(this).val()=='Yes') {
$('#seniordis').attr('disabled',false);
} else


$('#seniordis').removeAttr('disabled', true);
});
</script>



</head>



Senior :

<input name="senior" type="radio" id="Yes" value="Yes" />Yes
<input name="senior" type="radio" id="No" value="No" selected="selected" />No<br />
<select name="seniordis" id="select">
<option value="100" >100% discount</option>
<option value="50">50% discount</option>
<option value="10">10% discount</option>
</select>
</td>

Answer

Your problem is, senoirdis is name not a id. Your id is select.

$().ready(function()
{
    $('input:radio[name="senior"]').change(function() {
        if ($(this).val()=='Yes') {
            $('#select').prop('disabled',false);
        } 
        else
        {
            $('#select').prop('disabled',true);
        }
    });

});