0

I have a model of the question, answer id. question.answer7[20] && question.answer7[25].

How to convert this ng-model back to HTML and Javascript (or jQuery).

<md-checkbox ng-model="question.answer7[20]" ng-true-value="'69'">CheckboxA</md-checkbox>
<md-checkbox ng-model="question.answer7[25]" ng-true-value="'24'">CheckboxB</md-checkbox>

I have tried to put the input name answer7[20] and answer7[25]. And try console $('input[name="answer7"]'), but seem like jQuery not understand and return null;

<input name="answer7[20]" type="checkbox" checked value="69">CheckboxA
<input name="answer7[25]" type="checkbox" checked value="24">CheckboxB

console.log($('input[name="answer7"]')); // return null

Sorry for my poor English.

1 Answer 1

2

Try this:

console.log($('input[name^="answer7"]'));
Sign up to request clarification or add additional context in comments.

6 Comments

Thank you. It's work. But is there a way to get checked value as json? Example: {20: 69, 25: 24}
Can you please upvote and accept this answer first as it works for your original question? :)
For your second question I would say you need write code when checkbox is checked and then create object the way you want.
I only can upvote and accept after 5 min. Stackoverflow blocking me upvote and accept in 5min.
Seem like I must use attribute data for the 2nd value.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.