tags:

views:

30

answers:

3

So i have this structure

<div class="accordionContent">
<form action="/make_requests" class="make_request" method="post"><div style="margin:0;padding:0;display:inline"><input name="authenticity_token" type="hidden" /></div>                                                         
<tr>
    <td>Enter Sandman</td>
    <td>2</td>

    <td class="money">$0.00</td>
    <td>    
            <input class="yes_please" id="group_7,1,2_yes" name="group[7,1,2]" type="radio" value="yes" />
        Yes
            <input checked="checked" id="group_7,1,2_no" name="group[7,1,2]" type="radio" value="no" />
        No
    </td>
<tr>
    <td>Fade to Black</td>
    <td>2</td>
    <td class="money">$0.00</td>
    <td>    
            <input class="yes_please" id="group_3,6_yes" name="group[3,6]" type="radio" value="yes" />
        Yes
            <input checked="checked" id="group_3,6_no" name="group[3,6]" type="radio" value="no" />
        No
    </td>
</tr>
  <tr><td><input id="make_requests" name="commit" type="submit" value="Add to Set" /></td><td><span class="band_notice">Set Added</span></td></tr>
</form>

I need to only make the input enabled if at least one of the radio buttons is yes ...any ideas how to do this in jQuery

+1  A: 

Add disabled="disabled" to the input in the html, and add this piece of js:

$('input[type=radio]').change(function() {
    $('input[type=submit]').attr('disabled', true);
    $('input[type=radio][value=yes]:checked').first().each(function() {
        $('input[type=submit]').removeAttr('disabled');
    });
});
cambraca
+2  A: 
$("input:radio").change(function(){
    var checked = $("input:checked");
    if ($("input[value='yes']", checked).length > 0)
        { $('#make_requests').attr('disabled',''); }
    else
        {$('#make_requests').attr('disabled','disabled');}
});

THis binds a function to the change event of all checkboxes, gets all the checked inputs, then counts the number of those that have the value "yes". If it is more than 0 it enables the submit button, if less it disables.

Chao
+1  A: 

This worked for me...

<script type="text/javascript">
    $(function () {
        $('input:radio').change(function () {
            if($('.yes_please:checked').length)
                $('#make_requests').removeAttr('disabled');
            else
                $('#make_requests').attr('disabled', 'disabled');
        });
    });
</script>
Brian