$(document).ready(function(){
        $counter = 0; // initialize 0 for limitting textboxes
        $('#buttonadd').click(function(){
            if ($counter < 10)
            {
                $counter++;
                $('#buttondiv').append('<div class="ash_box_inside" style="border-bottom: 1px solid #c8c8ca; float:left;">  <div class="ash_box_inside_inner" style="text-align: right;"><a onclick="#" style="cursor: pointer;"><span style="color: #7e7e7e;">X</span> <span style="color: #fcba25;">Supprimer</span></a></div><div class="ash_box_inside_inner"><input type="radio" name="fields['+$counter+'][civilite]" value="Mr" style="margin-left: 10px;" /> Mr <input type="radio" fields['+$counter+'][civilite] value="Mme" checked /> Mme <input type="radio" fields['+$counter+'][civilite] value="Mlle" /> Mlle</div><div class="ash_box_inside_inner"><div class="name_search_res" style="float:left; margin-left: 13px; margin-top: 8px;">Nom<span style="color: #ff9608;">  *</span></div><input name="fields['+$counter+'][nom]" type="text" class="txt_input" style="float:left; margin-left: 8px; width: 198px;"/><div class="name_search_res" style="margin-left: 38px; margin-top: 8px;">Prem<span style="color: #ff9608;">  *</span></div><input name="fields['+$counter+'][prem]" type="text" class="txt_input" style="float:right; margin-left: 8px; width: 200px;"/></div> <div class="ash_box_inside_inner"><div class="name_search_res" style="margin-left: 13px;">Adresse<span style="color: #ff9608;">  *</span></div><textarea class="txt_area_input" cols="45" rows="5" name="fields['+$counter+'][adresse]" style="width: 462px; float: right; margin-top: 0px;"></textarea></div><div class="ash_box_inside_inner"><div class="name_search_res" style="margin-left: 13px; margin-top: 8px;">Code postal<span style="color: #ff9608;">  *</span></div><input name="fields['+$counter+'][postal]" type="text" class="txt_input" style="float:left; margin-left: 8px; width: 180px;"/><div class="name_search_res"  style="margin-left: 15px; margin-top: 8px;">Ville<span style="color: #ff9608;">  *</span></div><input name="fields['+$counter+'][ville]" type="text" class="txt_input" style="float:right; margin-left: 8px; width: 200px;"/></div><div class="ash_box_inside_inner"><div class="name_search_res" style="margin-left: 13px; margin-top: 8px;">Telephone<span style="color: #ff9608;">  *</span></div><input name="fields['+$counter+'][telephone]" type="text" class="txt_input"  style="float:left; margin-left: 8px; width: 188px;"/><div class="name_search_res"  style="margin-left: 15px; margin-top: 8px;">Email<span style="color: #ff9608;">  *</span></div><input name="fields['+$counter+'][email]" type="text"  class="txt_input" style="float:right; margin-left: 8px; width: 200px;"/></div><div class="ash_box_inside_inner" style="border-top: 1px solid #c8c8ca; width: 100%; padding-top: 15px; padding-bottom: 15px;"><table width="100%" style="margin-left: 9px; font-size: 11px;"><tr><td style="text-align: left; color: #797f97; font-weight: bold;"><input name="fields['+$counter+'][regulier]" type="checkbox" /><span class="ash_bottom_text_align">Régulier dans ma cellule</span></td><td style="text-align: left; color: #797f97; font-weight: bold;"><input name="fields['+$counter+'][dejac]" type="checkbox" /><span class="ash_bottom_text_align">Déjà converti</span></td><td style="text-align: left; color: #797f97; font-weight: bold;"><input name="fields['+$counter+'][pas]" type="checkbox" /><span class="ash_bottom_text_align">Pas encore sauvé</span></td></tr><tr><td style="text-align: left; color: #797f97; font-weight: bold;"><input name="fields['+$counter+'][nouveauc]" type="checkbox" /><span class="ash_bottom_text_align">Nouveau dans ma cellule</span></td><td style="text-align: left; color: #797f97; font-weight: bold;"><input name="fields['+$counter+'][sauve]" type="checkbox" /><span class="ash_bottom_text_align">Sauvé aujoud’hui</span></td><td style="text-align: left; color: #797f97; font-weight: bold;"><input name="fields['+$counter+'][deja]" type="checkbox" /><span class="ash_bottom_text_align">Déjà allé à PCC</span></td></tr><tr><td style="text-align: left; color: #797f97; font-weight: bold;"><input name="fields['+$counter+'][enfant]" type="checkbox" /><span class="ash_bottom_text_align">Enfant</span> <input name="fields['+$counter+'][age]" style="width:40px" type="text" class="txt_input" /> <span class="ash_bottom_text_align">àge</span></td></tr></table></div></div>');
                document.getElementById("counters").value = $counter;
               // alert($counter);
            }else{
                alert('You cannot add more than 10');
            }
        });

        $('#buttonremove').click(function(){
            alert($counter);
            if ($counter){
                $counter--;
                $('#buttondiv .textbox:last').parent().remove(); // get the last textbox and parent for deleting the whole div
                //$('#buttondiv').remove('<div class="ash_box_inside" style="border-bottom: 1px solid #c8c8ca; float:left;">  <div class="ash_box_inside_inner" style="text-align: right;"><a onclick="#" style="cursor: pointer;"><span style="color: #7e7e7e;">X</span> <span style="color: #fcba25;">Supprimer</span></a></div><div class="ash_box_inside_inner"><input type="radio" name="group1" value="Mr" /> Mr <input type="radio" name="group1" value="Mme" checked /> Mme <input type="radio" name="group1" value="Mlle" /> Mlle</div><div class="ash_box_inside_inner"><div class="name_search_res" style="float:left; ">Nom<span style="color: #ff9608;">  *</span></div><input name="fields['+$counter+'][nom]" type="text" class="txt_input" style="float:left; margin-left: 8px; width: 198px;"/><div class="name_search_res" style="margin-left: 40px;">Prem<span style="color: #ff9608;">  *</span></div><input name="fields['+$counter+'][prem]" type="text" class="txt_input" style="float:left; margin-left: 8px; width: 200px;"/></div> <div class="ash_box_inside_inner"><div class="name_search_res">Adresse<span style="color: #ff9608;">  *</span></div><textarea class="txt_area_input" cols="45" rows="5" name="fields['+$counter+'][adresse]" style="width: 450px; float: left; margin-left: 30px;"></textarea></div><div class="ash_box_inside_inner"><div class="name_search_res">Code postal<span style="color: #ff9608;">  *</span></div><input name="fields['+$counter+'][code-postal]" type="text" class="txt_input" style="float:left; margin-left: 8px; width: 188px;"/><div class="name_search_res"  style="margin-left: 15px;">Ville<span style="color: #ff9608;">  *</span></div><input name="fields['+$counter+'][ville]" type="text" class="txt_input" style="float:left; margin-left: 8px; width: 200px;"/></div><div class="ash_box_inside_inner"><div class="name_search_res">Telephone<span style="color: #ff9608;">  *</span></div><input name="fields['+$counter+'][telephone]" type="text" class="txt_input"  style="float:left; margin-left: 8px; width: 188px;"/><div class="name_search_res"  style="margin-left: 20px;">Email<span style="color: #ff9608;">  *</span></div><input name="fields['+$counter+'][email]" type="text"  class="txt_input" style="float:left; margin-left: 8px; width: 200px;"/></div><div class="ash_box_inside_inner" style="border-top: 1px solid #c8c8ca; width: 100%; padding-top: 15px; padding-bottom: 15px;"><table width="100%"><tr><td style="text-align: left; color: #797f97; font-weight: bold;"><input name="fields['+$counter+'][regulier-cellule]" type="checkbox" />Régulier dans ma cellule</td><td style="text-align: left; color: #797f97; font-weight: bold;"><input name="fields['+$counter+'][deja-converti]" type="checkbox" />Déjà converti</td><td style="text-align: left; color: #797f97; font-weight: bold;"><input name="fields['+$counter+'][pas-encore-sauve]" type="checkbox" />Pas encore sauvé</td></tr><tr><td style="text-align: left; color: #797f97; font-weight: bold;"><input name="fields['+$counter+'][nouveau-cellule]" type="checkbox" />Nouveau dans ma cellule</td><td style="text-align: left; color: #797f97; font-weight: bold;"><input name="fields['+$counter+'][sauve-aujoudhui]" type="checkbox" />Sauvé aujoud’hui</td><td style="text-align: left; color: #797f97; font-weight: bold;"><input name="fields['+$counter+'][deja-alle-a-pcc]" type="checkbox" />Déjà allé à PCC</td></tr><tr><td style="text-align: left; color: #797f97; font-weight: bold;"><input name="fields['+$counter+'][enfant]" type="checkbox" />Enfant <input name="fields['+$counter+'][age]" style="width:50px" type="text" /> àge</td></tr></table></div></div>');
            }else{
                alert('No More textbox to remove');
            }
        });

        $('#buttonget').click(function(){
            alert($('.textbox').serialize()); // use serialize to get the value of textbox
        });

        /*$('#dropdownadd').change(function(){
            $('#dropdowndiv').html("");
            $loopcount = $(this).val();
            for (var i = 1; i <= $loopcount; i++)
            {
                $('#dropdowndiv').append('<div><label>Textbox #'+i+'</label><input type="text" name="textbox2[]" class="textbox2" value="" /></div>');
            }
        });*/
    });
