jQuery: seleccione la casilla de verificación según el nombre y el valor
Tengo el siguiente 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>
Y estoy tratando de implementarselectCheckbox( chkbox, value)
, que debería:
name = chkbox
y establecerattr('checked') = false
buscar la radio que tienename = chkbox AND val() = value
y establecerattr('checked') = true
No puedo entender qué es el selector correcto, probé lo siguiente sin suerte:
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'
Por favor, déjame saber lo que estoy haciendo mal. ¡Muchas muchas gracias!