I have the following HTML:
<form id="test">
<input type="radio" value="A" name="C1"/>
<a href="javascript:selectCheckbox('C1', 'A');"> OPTION-A </a>
<input type="radio" value="B" name="C1"/>
<a href="javascript:selectCheckbox('C1', 'B');"> OPTION-B </a>
<input type="radio" value="C" name="C1"/>
<a href="javascript:selectCheckbox('C1', 'C');"> OPTION-C </a>
// several other: C2, C3, ..
</form>
And I'm trying to implement selectCheckbox( chkbox, value)
, which should:
- search for all radio's with
name = chkbox
and setattr('checked') = false
- search for the radio having
name = chkbox AND val() = value
and setattr('checked') = true
I can't figure out, what the right selector is, I tried the following without any luck:
var name = "#" + chkbox + " :checked";
$(name).each(.. // doesn't work
$('#'+chkbox).each( .. // if finds only the first occurence
// of i.e. C1, although I would expect 3
$("input[@name='"+chkbox+"']").each( function() { ..
// leaves me with the following error:
// Warning: Expected attribute name or namespace but found '@name'
Please let me know what I'm doing wrong. Many, many thanks!