views:

169

answers:

2

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?

+1  A: 

You need to serialize your input with - serialize()

var data = $('#MYFORM').serialize();
Ivo Sabev
+1  A: 

You can use jQuery's each() function.

$('input.radio:checked').each(function() {
  //put each of the selected check boxes into an array
});
Jonathan Mayhak