1

I am trying to log some input values into an array via jquery and then use those to run a method server side and get the data returned as JSON.

The HTML looks like this,

    <div class="segment">
               <div class="label">
                <label>Choose region: </label>
               </div>


<div class="column w190">
                    <div class="segment">
                        <div class="input">
                            <input type="checkbox" class="radio" value="Y" name="area[Nationwide]" id="inp_Nationwide">
                        </div>
                        <div class="label ">
                            <label for="inp_Nationwide">Nationwide</label>
                         </div>
                        <div class="s">&nbsp;</div>
                    </div>

</div>

<div class="column w190">
                    <div class="segment">
                        <div class="input">
                            <input type="checkbox" class="radio" value="Y" name="area[Lancashire]" id="inp_Lancashire">
                        </div>
                        <div class="label ">
                            <label for="inp_Lancashire">Lancashire</label>
                         </div>
                        <div class="s">&nbsp;</div>
                    </div>

</div>

<div class="column w190">
                    <div class="segment">
                        <div class="input">
                            <input type="checkbox" class="radio" value="Y" name="area[West_Yorkshire]" id="inp_West_Yorkshire">
                        </div>
                        <div class="label ">
                            <label for="inp_West_Yorkshire">West Yorkshire</label>
                         </div>
                        <div class="s">&nbsp;</div>
                    </div>
               <div class="s">&nbsp;</div>
       </div>

I have this javascript the detect whether the items are checked are not

if($('input.radio:checked')){

}

What I dont know is how to get the values of the input into an array so I can then send the information through AJAX to my controller. Can anyone help me?

2 Answers 2

1

You can use jQuery's each() function.

$('input.radio:checked').each(function() {
  //put each of the selected check boxes into an array
});
Sign up to request clarification or add additional context in comments.

Comments

1

You need to serialize your input with - serialize()

var data = $('#MYFORM').serialize();

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.