javascript - Concatenate variable into radio button selector -
i trying find value of checked radio button. concatenating variable 'flagname' input selector, , keeps returning undefined. here jquery:
function filterprojects (searchinput) { var filter = $(searchinput).val(), count = 0; var $projects = $(".projectdisplay"); $projects.show(); $projects.each(function () { var $currentproject = $(this); var projectflags = $(this).data(); (var flagname in projectflags) { var flagvalue = projectflags[flagname]; var checkedinputvalue = $("input[name='" + flagname + "']:checked", "#flagsearchform").val(); if ((checkedinputvalue == "yes" && flagvalue == "0") || (checkedinputvalue == "no" && flagvalue == "1")) { $currentproject.hide(); } } if ($(this).find(".projectname").text().search(new regexp(filter, "i")) < 0) { $(this).hide(); } });
}
i trying find value of checkedinputvalue. flagname , flagvalue both return supposed to. in html, have form loops through php array create multiple fieldsets have 3 radio buttons each. here part of html form is:
<form id="flagsearchform" name="flagform"> <div class="grid-unit grid-unit-9-14"> <h4>search flag value</h4> <div class="flagsearch"> <div class="wrapper grids"> <?php $flag_names = array("hasbib", "haschoice", "hasebooks", "hasfrbr", "haslcd","hasltp", "hasnlm", "haspeers", "includedewey", "includegovtdocs", "includenonbooks", "includeopacurl", "includeprotection", "includescores"); ?> <?php foreach ($flag_names $i=>$flag_name): ?> <div class="flagfields"> <div class="grid-unit grid-unit-3-14"> <fieldset> <span class="flagname"><?php echo $flag_name; ?></span> <input type="button" value="n/a" class="tri-state ignore" id="<?php echo $flag_name; ?>"/> <input type="radio" name="<?php echo $flag_name; ?>" value="ignore" id="<?php echo $flag_name; ?>-ignore" class="radio-button" checked><label for="<?php echo $flag_name; ?>-ignore">ignore</label> <input type="radio" name="<?php echo $flag_name; ?>" value="yes" id="<?php echo $flag_name; ?>-yes" class="radio-button"><label for="<?php echo $flag_name; ?>-yes">yes</label> <input type="radio" name="<?php echo $flag_name; ?>" value="no" id="<?php echo $flag_name; ?>-no" class="radio-button"><label for="<?php echo $flag_name; ?>-no">no</label> </fieldset> </div> </div> <?php endforeach; ?> </div> </div> <input type="submit" value="submit" class="flagsearchsubmit"> </div>
is syntax checkedinputvalue wrong?
i'm not sure filter/regex need completed. logs selected inputs.
here fiddle: https://jsfiddle.net/c4qbywrt/7/
function filterprojects(searchinput) { $('input:radio').each(function () { if ($(this).is(':checked')) { var $currentproject = $(this); var checkedinputvalue = $(this).val(); var flagvalue = '0'; // not sure setting if ((checkedinputvalue == "yes" && flagvalue == "0") || (checkedinputvalue == "no" && flagvalue == "1")) { $currentproject.hide(); } var filter = ''; if ($(this).find(".projectname").text().search(new regexp(filter, "i")) < 0) { $(this).hide(); } } }); } $("#searchprojects").keyup(function () { filterprojects($(this)); }); $("#flagsearchform").submit(function (event) { event.preventdefault(); filterprojects($("#searchprojects")); });
Comments
Post a Comment