when you do $('input[id$=9]').is(":checked"), an array of all matched
elements is returned. So you can do this:
var checkedNAItems = $('input[id$=9]').is(":checked");
and that should should get you an array of all elements. from there,
you can loop through them and extract the info you need with .attr
("id") and a substring() for each item.
or you can keep to the jquery goodness and use the each function:
$('input[id$=9]').is(":checked").each(function (notApplicableItem)
{
var idNumber = notApplicableItem.attr("id");
var firstPortion = substr(0,idNumber.length-1);
//do more stuff
});
i'm just typing this out and it's not been tested, so this code'll
prob not work, but you get the idea.
hope that helps!
On Dec 28, 8:00 am, Noogrub <[email protected]> wrote:
> I have a table which has a series of rows having ids like this:
> <tr id="XYZ101a">
> <tr id="PDQ101a">
>
> Each row has several radio buttons representing answers in an online
> survey named like so:
> <input type="radio" id="XYZ101a1">
> <input type="radio" id="XYZ101a2">
> <input type="radio" id="XYZ101a3">
> <input type="radio" id="XYZ101a4">
> <input type="radio" id="XYZ101a9">
>
> There are many such table rows, and all that ever changes in their ids
> is the initial portion. (There's an ABC101a, a PDQ101a, etc). I am
> not allowed to change the input ids, as they are created in another
> department to adhere to some standardized schema. The answers always
> follow the format, too, and the answers ending with "9" are "Not
> applicable".
>
> I'm stuck on my task, which is to hide the question if "Not
> applicable" is chosen. In other words, my task is to notice whenever
> someone clicks on the last answer, which always ends in "9", and then
> use that selector to hide the whole row, which has as its ID the first
> portion of the id of the radio button ending in "9".
>
> So far I can react when the radio id ending in "9" is chosen using:
> if( $('input[id$=9]').is(":checked") ) { //hide the whole row in
> which this question resides}
>
> However, how can I grab the FIRST portion of the input id, which
> matches the row id I then need to hide? In perl, I'd use $' to
> represent the portion BEFORE the part I matched. How can I do this in
> jQuery? Any assistance appreciated. I don't seem to quite grok what
> jQuery does with its temp variables once a match is found.
>
> Thanks.