0

Im stuck on getting check box's value here. Following is my code.

<script type="text/javascript">
    fnChkGrp = function() {
        alert($('#reqType').val()
    )}
</script>   

<form id="frm" name="frm" method="post" action="">
    <input type="hidden" id="reqType" name="reqType"/>
    <table class="tableBB mgT10" >
        <tr>
            <td>
                <span id="reqType" style="display:block;">
                    <span class="chk"><label><input type="checkbox" id="normal" name="normal" value="normalChk"/>A</label></span>
                    <span class="chk"><label><input type="checkbox" id="urgent" name="normal" value="urgentChk"/>B</label></span>
                </span>     
            </td>

            <div class="area_btnA clfix mgB20">
                <a href="#" onclick="fnChkGrp();return false;" class="btnA"><strong>CHECK</strong></a>
            </div> 

So when I check the "A", its its value "normalChk" should be sent through frm. Ans when I click on the CHECK button, its value should be displayed. But for some reason, it doesn't work. Can anyone tell me why? and How to fix it?

Thilina Sampath
  • 3,615
  • 6
  • 39
  • 65
user2470075
  • 171
  • 3
  • 5
  • 23

2 Answers2

2

You can try this:

if($('input[name=normal]').prop(':checked').val()==true)
{
    alert("Checked");
}
else
{
    alert("Unchecked");
}

.prop get the value of a property for the first element in the set of matched elements.

Prateek
  • 6,785
  • 2
  • 24
  • 37
0

Try this:

fnChkGrp = function() {
   var checkboxes = document.getElementsByName("normal");
    for (var i = 0; i < checkboxes.length; i++)
    {
        if (checkboxes[i].checked)
            alert(checkboxes[i].value);
    }
}

HTML:

<form id="frm" name="frm" method="post" action="">
<input type="hidden" id="reqType" name="reqType"/>
<table class="tableBB mgT10" >
<tr>

    <td>
        <span id="reqType" style="display:block;">
            <span class="chk"><label><input type="checkbox" id="normal" name="normal" value="normalChk"/>A</label></span>
            <span class="chk"><label><input type="checkbox" id="urgent" name="normal" value="urgentChk"/>B</label></span>
        </span>     
    </td>
    </tr>
</table>
    <div class="area_btnA clfix mgB20">
        <a href="#" onclick="fnChkGrp();return false;" class="btnA"><strong>CHECK</strong></a>
    </div>
</form>
Bhushan
  • 6,151
  • 13
  • 58
  • 91