using jquery to find radiobutton groups with no answers -
i've been racking brain find better solution following situation.
imagine page lot of radiobuttons on it, , having custom validation highlighting groups of radiobuttons haven't been answered.
example html (with answers preselected):
<input type='radio' name='a' value='1' /> <input type='radio' name='a' value='2' /> <input type='radio' name='a' value='3' /> <input type='radio' name='b' value='1' checked="checked"//> <input type='radio' name='b' value='2' /> <input type='radio' name='b' value='3' /> <input type='radio' name='c' value='1' /> <input type='radio' name='c' value='2' checked="checked"/> <input type='radio' name='c' value='3' /> <input type='radio' name='d' value='1' /> <input type='radio' name='d' value='2' /> <input type='radio' name='d' value='3' />
i've written bit of jquery want, know can done better/faster/prettier/more efficiently.
//select radiobuttons var $radios = $("input[type='radio']") //loop through radios checked $($radios+":checked").each(function(){ //filter out radios current name, , add recognize them $($radios).filter("[name='" + $(this).attr("name") + "']").addclass("checked") }); //find radios without class checked, , highlight them var $unchecked_radios = $($radios + ":not(.checked)").addclass("highlight");
but i'm stuck on how combine two, subtracting ones have answer entire population of radios.
(although suspect there might better way select groups of radiobuttons same name)
any appreciated!
regards, casper
i don't know if can help, here code :
$(document).ready(function() { $('input:not(:checked)').each(function() { if($('input[name='+$(this).attr('name')+']:checked').size() == 0) { $(this).addclass('highlight'); } }); });
with this, highlight unchecked radio of groups don't have radio checked yet. fit need?
Comments
Post a Comment