I have 3 checkboxes but they are showing as undefined in an alert box. Is there a trick to getting them to show a value? I tried putting a value of 1 in the input tag but it still reports as undefined.
Ok, thanks.. Here is some code.
else if (item.field == "admCustRptDly" && item.value == "1")
{
$('#admCustRptDly').attr('checked', true);
}
else if (item.field == "admCustRptSumm" && item.value == "1")
{
$('#admCustRptSumm').attr('checked', true);
}
else if (item.field == "admCustRptDtl" && item.value == "1")
{
$('#admCustRptDtl').attr('checked', true);
}
<input type="checkbox" id="admCustRptDly" name="admCustRptDly" class="admChkbx">
<input type="checkbox" id="admCustRptSumm" name="admCustRptSumm" class="admChkbx">
<input type="checkbox" id="admCustRptDtl" name="admCustRptDtl" class="admChkbx">
I have 3 checkboxes but they are showing as undefined in an alert box. Is there a trick to getting them to show a value? I tried putting a value of 1 in the input tag but it still reports as undefined.
Ok, thanks.. Here is some code.
else if (item.field == "admCustRptDly" && item.value == "1")
{
$('#admCustRptDly').attr('checked', true);
}
else if (item.field == "admCustRptSumm" && item.value == "1")
{
$('#admCustRptSumm').attr('checked', true);
}
else if (item.field == "admCustRptDtl" && item.value == "1")
{
$('#admCustRptDtl').attr('checked', true);
}
<input type="checkbox" id="admCustRptDly" name="admCustRptDly" class="admChkbx">
<input type="checkbox" id="admCustRptSumm" name="admCustRptSumm" class="admChkbx">
<input type="checkbox" id="admCustRptDtl" name="admCustRptDtl" class="admChkbx">
Share
Improve this question
edited Apr 3, 2009 at 9:06
asked Apr 3, 2009 at 8:54
TomTom
3 Answers
Reset to default 2your jquery is off, this doesn't quite give the response you'd expect, rather to find if a check box is checked:
var checked = $("#admCustRptDtl:checked").val();
Also, the checked attribute will never equal true, the html is actually checked="checked"
else if (item.field == "admCustRptDly" && item.value == "1")
I don't understand what are you trying to do here? I'm guessing you are trying to verify the value of "admCustRptDply" checkbox. Maybe post also the code before this. You can get the value like this:
var val = $("#admCustRptDly").val()
But in your HTML the checkboxes don't have a value attribute.
You can get the checked property of a checkbox like this:
var checked = $("#admCustRptDly").attr("checked")
And you can set it like this:
$("#admCustRptDly").attr("checked","checked")
Could you please expand? Some example code would be very helpful, you might've just misspelt the checkbox name when trying to use it.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745671750a4639445.html
评论列表(0条)