I am setting up a form for user to fill and I can get 1 value but I want to get 2 values and set custom array.right now it is just

[A,B]

But I have 2 values 1 for which option is selected which is value and 1 for question Id which is data-value.

So I need the array like this

[{"selection": "A", "question_id": "13"},{"selection": "B", "question_id": "14"}]

since question and answers getting from the database I cant manually make the array.

This is my listing part

 <input type="radio" class="mybox" value="@opt[i].Order" data-value="@item.Id"> <label>@opt[i].Body</label>

And here is my javascript to get

[A,B]

<script>
   $("#save_value").click(function(event){
   event.preventDefault();
   var searchIDs = $("input:radio:checked").map(function(){
   return this.value;}).toArray();
   alert(searchIDs);
   })
</script>

AS I mentioned I want to change format to expected format

[{"selection": "A", "question_id": "13"},{"selection": "B", "question_id": "14"}]

0 Answers