0

I have a html form content with two check boxes like

<p class="text">
                <input type="checkbox" value="Yes" id="ques11" name="radiobutton" class="option_1" />
                <label for="ques11">True</label>
                <span class="hide" id="ans1">Answer: True</span>
                <span id="rite11" class="hide"><img class="imgsize" src="images/ans_correct.png"/></span>
                <span id="wrong11" class="hide"><img class="imgsize" src="images/ans_wrong.png"/></span> </p>

            <p class="text">
                <input type="checkbox" value="No" id="ques12" name="radiobutton" class="option_2" />
                <label for="ques12">False</label>
                <span id="rite12" class="hide"><img class="imgsize" src="images/ans_correct.png"/></span>
                <span id="wrong12" class="hide"><img class="imgsize" src="images/ans_wrong.png"/></span> </p>

for this i have written code to get the checkboxes

   $(function(){
    $('#_submit').on('click', function(){
     completedata = 'selected_';
            $('input[type="checkbox"]').each(function(){

   var quesNo = $(this).closest("div[id^='questionsNo_']").attr('id').split('_');
 var chapterId = quesNo[1]; 
 var questionId = quesNo[2];
 var optionId = $(this).attr('class').split('_')[1];
var currentAns = $(this).val();
 completedata += 'choose'+','+chapterId + ',' + questionId + ',' + optionId + ',' + currentAns + '_';
  completedata = completedata.substr(0, completedata.length - 1) + '_selectedEnd';
  if(completedata == "selected_selectedEnd"){

          document.getElementById("selids").innerHTML="";
  }

    else {
        $('#selids').text(completedata);
                 } 

In this line i have to get which checkbox is checked, how to get that using this script. Please help me how to do that.

 var optionId = $(this).attr('class').split('_')[1];

i want which check box is clicked based on class="option_1" or class="option_2".

2
  • $('.'+ optionId).val() Commented Jul 27, 2016 at 6:12
  • You can refer this link : tutorialrepublic.com/faq/… Commented Jul 27, 2016 at 6:16

1 Answer 1

1

Try this:

$("input[name='radiobutton']").click(function(){
  if($(this).is(':checked'))
{
    // checked
}
else
{
   // unchecked
}
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.