views:

781

answers:

3

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">
+1  A: 

Could you please expand? Some example code would be very helpful, you might've just misspelt the checkbox name when trying to use it.

Andrei Serdeliuc
Thanks for the help! I posted some code above. I'm sure its simple but I haven't a clue.
+2  A: 

your 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"

Jeremy B.
+2  A: 
 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")
Béres Botond