MB34
MB34

Reputation: 4404

JQuery->Check if group of radios has any selected

<table width="100%">
    <tbody>
        <tr id="InfoCol_1158341_NY" class="InfoCol">
             <td width="50%" id="InfoType_221832" class="TypeCol">
                 <input type="radio" value="221832" name="lt_1158341_221832" id="lt_1158341_221832" class="lt_">
                 <br><label id="lbl_lt_1158341_221832" for="lt_1158341_221832" class="lt_ ">Linse 1<br>Hours: 8</label>
                 <input type="hidden" name="hr_1158341_221832" id="hr_1158341_221832" value="8" class="hr_">
                 <input type="hidden" name="un_1158341_221832" id="un_1158341_221832" value="0" class="un_">
                 <input type="hidden" name="pr_1158341_221832" id="pr_1158341_221832" value="8" class="pr_">
             </td>
             <td width="50%" id="InfoType_221833" class="TypeCol">
                 <input type="radio" value="221833" name="lt_1158341_221833" id="lt_1158341_221833" class="lt_">
                 <br><label id="lbl_lt_1158341_221833" for="lt_1158341_221833" class="lt_ ">Linse 2<br>Hours: 1</label>
                 <input type="hidden" name="hr_1158341_221833" id="hr_1158341_221833" value="1" class="hr_">
                 <input type="hidden" name="un_1158341_221833" id="un_1158341_221833" value="0" class="un_">
                 <input type="hidden" name="pr_1158341_221833" id="pr_1158341_221833" value="1" class="pr_">
             </td>
         </tr>
    </tbody>
</table>

Neither one of the below selectors returns the radios. I need to know if neither one is checked. Note: PID is passed and value is 1158341

$(radio[name^="lt_'+PID+'"]')


$('.TypeCol radio[name^="lt_'+PID+'"]')

Can't do it by class because the inputs COULD be hidden vs. radio in this dynamically created form.

Upvotes: 0

Views: 58

Answers (1)

Blazemonger
Blazemonger

Reputation: 92893

The selector:

$('input[type=radio][name^="lt_'+PID+'"]')

To see if either is checked:

if ($('input[type=radio][name^="lt_'+PID+'"]:checked').length > 0) {

http://api.jquery.com/checked-selector/

Upvotes: 2

Related Questions