JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<form>
<input type="radio" name="size" value="small" checked> Small<br>
<input type="radio" name="size" value="medium"> Medium<br>
<input type="radio" name="size" value="large"> Large<br><br>
<label for="pizza11">Two Types of Pizza in One Click Here: </label>
<input type="checkbox" name="half1" id="pizza11" value="One Half: "/><br />
<!--Size1 End-->
<!--Type1-->
<label for="pizzaoption1">Select Your 1st Pizza</label>
<select name="pizzaoption1" id="pizzaoption1" onchange="sourcetype(this.value)">
<option value="none" >None</option>
<option value="dheese" title="cheese">Cheese</option>
<option value="pepperoni" title="pepperoni">Pepperoni</option>
<option value="hawaiian" title="ham and pineapple">Hawaiian</option>
<option value="canadian" title="Ham, Bacon, Tomatoes, Onions, and Cheddar Cheese.">Canadian</option>
<option value="freshgarden" title="Mushrooms, Green Peppers, Onions, Olives, Tomatoes, Pineapple, and a sprinkle of Basil">Fresh Garden Vegetarian</option>
<option value="classic" title="Pepperoni, Mushrooms, and Green Pepper">Baldy's Classic</option>
<option value="donair" title="Donair Meat, Onions, and Tomatoes on Donair Sweet Sauce">Donair Pizza</option>
<option value="bbqchicken" title="Chicken, Bacon, Pineapple, Mushrooms, Onions and Cheddar Cheese on a BBQ sauce">BBQ Chicken</option>
<option value="housepecial" title="Pepperoni, Ham, Lean Beef, Mushrooms, Green Peppers, Onions, Olives, and Tomatoes">House Special</option>
<option value="buffalochicken" title="Chicken, Onions, Mushrooms, Bacon, Mexican Spices and Cheddar Cheese on a Hot Sauce base">Buffalo Chicken</option>
<option value="tropicchicken" title="Chicken, Pineapple, Bacon and Cheddar Cheese on a Tangy Tropical base.">Tropical Chicken</option>
<option value="tropichawaiian" title="Ham, Pineapple, Bacon and Cheddar...
JavaScript
function serialize (form_object, which){ // 'which' can be set to 'object' (default) or 'array'
var this_object = {},
context,
count = 0;
form_object.find('input,select,textarea').each(function(){
this_object = $(this);
// If radio-button and checked AND not submit button
if (
((this_object.attr('type') != 'radio') || (this_object.is(':checked'))) &&
(this_object.attr('type') != 'submit') &&
(typeof this_object.attr('name') !== 'undefined')
){
if ((typeof which === 'undefined') || (which == 'object')) { // if object requested
if (typeof context === 'undefined')
context = {};
context[this_object.attr('name')] = (this_object.attr('type') == 'checkbox') ? this_object.is(':checked') : this_object.val(); // if checkbox, record boolean for 'checked' -- otherwise, record the value
}
else{ // if array requested
if (typeof context === 'undefined')
context = [];
context.push({
name : this_object.attr('name'),
value : (this_object.attr('type') == 'checkbox') ? this_object.is(':checked') : this_object.val() // if checkbox, record boolean for 'checked' -- otherwise, record the value
});
}
count++;
}
});
return context;
}
$(document).ready(function(){
$('form').submit(function(e){
e.preventDefault();
var serialized = serialize($(this));
console.log(serialized);
$.post( "process_file.php", {data: JSON.stringify(serialized)})
.done(function( data ) {
$('#inject').html(data)
});
});
});