0

I have a form like below:

   <form id="toppings_div" name="form1" method="post" action="">
                            <table width="355">
                              <tr>
                                <td>
                                  <input type="checkbox" value="Cheese" />
                                  <label>Extra cheese</label>
                                </td></tr></table></from>

I was just wondering how I can get to the value of the checkbox if it's checked.

thanks

        alert($('#toppings_div').children().children().children().children(':checked').val());

using the code above gives me an undefined answer,

thanks

3 Answers 3

1

$('#toppings_div input:checkbox:checked').val() is all that's needed. The > in the selector means direct descendant of.

Sign up to request clarification or add additional context in comments.

Comments

1

I used the following line of code to solve my problem:

alert($('input:checked').val() );

1 Comment

This will get you the value of the first checked input on your page, make sure that's what you want.
0

Try .checked()

1 Comment

There is no function checked in jQuery

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.