asp.net mvc 4 - JQuery always returning false for checkbox value -
i'm working on c# mvc 4 project , having problems determining if checkbox checked using jquery. basically, need show , hide other controls on page based on value of checkbox. here cshtml code checkbox :
@if (model.skucustomizations[i].hasstonechange) { <div class="two-col-label">@html.displaynamefor(m => m.skucustomizations[i].stone_haschange)</div> <div id="divstonechange" data-idx="@i" class="two-col-value"> <input type="checkbox" id="chkstone_@i" name="stonechange" checked="@model.skucustomizations[i].stone_haschange"> </div> <div class="last" /> }
and here code try , pull checked value:
$('#divstonechange').change(function () { var idx = $('#divstonechange').attr('data-idx') var stone = $('#chkstone' + idx).is(':checked') if (stone != false) { $("#divvendorcost").show(); } else { var type = $('#ddmetaltype' + idx).val(); var mount = $('#chkmount' + idx).is(':checked') var subcat = $('#ddsubcat' + idx).val(); if (mount != true && (subcat == "whole set" || subcat == "" || subcat == "-- select --" || subcat == undefined) && (type == "-- not customized --" || type == "" || type == undefined)) { $("#divvendorcost").hide(); } } });
$('#chkstone' + idx).is(':checked')
returning false no matter value of checkbox. can point out i'm doing wrong?
thanks
you missed _
there in selector
var stone = $('#chkstone_' + idx).is(':checked'); //-----------^---here;
try this,
... var idx = $('#divstonechange').attr('data-idx'); if ($('#chkstone_' + idx).is(':checked')) { $("#divvendorcost").show(); } else { var type = $('#ddmetaltype' + idx).val(); var mount = $('#chkmount' + idx).is(':checked') var subcat = $('#ddsubcat' + idx).val(); if (mount != true && (subcat == "whole set" || subcat == "" || subcat == "-- select --" || subcat == undefined) && (type == "-- not customized --" || type == "" || type == undefined)) { $("#divvendorcost").hide(); } } ..
Comments
Post a Comment