In the form of a checkbox always sends ON, regardless of whether the checkbox is ticked or not. Why does he behave like this? How to make sending ON only when the checkbox is checked?

<form id="CalcForm" name="CalcForm" action="#" method="post"> <input id="wsize1" name="wsize1" type="hidden" value="165"> <input id="wsize2" name="wsize2" type="hidden" value="165"> <input id="wsize3" name="wsize3" type="hidden" value="165"> <input id="wsize4" name="wsize4" type="hidden" value="165"> <input id="dsize1" name="dsize1" type="hidden" value="165"> <input id="dsize2" name="dsize2" type="hidden" value="165"> <input id="type_window" name="type_window" type="hidden" value="okno"> <input id="col_stv" name="col_stv" type="hidden" value="2"> <input id="stv1" name="stv1" type="hidden" value="no"> <input id="stv2" name="stv2" type="hidden" value="no"> <input id="stv3" name="stv3" type="hidden" value="no"> <input id="furnitura" name="furnitura" type="hidden" value="Roto NT KSR"> <input id="glubina" name="glubina" type="hidden" value="250 ΠΌΠΌ Π Π‘Πš"> <input id="steklopaket" name="steklopaket" type="hidden" value="ΠžΠ΄Π½ΠΎΠΊΠ°ΠΌΠ΅Ρ€Π½Ρ‹ΠΉ"> <input id="profil" name="profil" type="hidden" value="- систСмы 58"> <input id="ruchka" name="ruchka" type="hidden" value="Π ΡƒΡ‡ΠΊΠ° Hoppe, бСлая"> <div class="dif_box_list dblmarg dblmargleft">Π€ΡƒΡ€Π½ΠΈΡ‚ΡƒΡ€Π°:<br> <div id="dd1" class="wrapper-dropdown-1" tabindex="1"> <span>Roto NT</span> <ul class="dropdown" tabindex="1" style="z-index: 50;"> <li><a href="#" id="furnitura1">Roto NT</a></li> <li><a href="#" id="furnitura2">Roto NT KSR</a></li> </ul> </div> </div> <div class="dif_box_list dblmarg">Π“Π»ΡƒΠ±ΠΈΠ½Π° ΠΏΠΎΠ΄ΠΎΠΊΠΎΠ½Π½ΠΈΠΊΠ°:<br> <div id="dd2" class="wrapper-dropdown-1" tabindex="1"> <span>Π¨ΠΈΡ€ΠΈΠ½Π° 150 ΠΌΠΌ Π Π‘Πš</span> <ul class="dropdown" tabindex="1" style="z-index: 50;"> <li><a href="#" id="glubina1">Π¨ΠΈΡ€ΠΈΠ½Π° 150 ΠΌΠΌ Π Π‘Πš</a></li> <li><a href="#" id="glubina2">200 ΠΌΠΌ Π Π‘Πš</a></li> <li><a href="#" id="glubina3">250 ΠΌΠΌ Π Π‘Πš</a></li> <li><a href="#" id="glubina4">300 ΠΌΠΌ Π Π‘Πš</a></li> <li><a href="#" id="glubina5">350 ΠΌΠΌ Π Π‘Πš</a></li> <li><a href="#" id="glubina6">400 ΠΌΠΌ Π Π‘Πš</a></li> <li><a href="#" id="glubina7">450 ΠΌΠΌ Π Π‘Πš</a></li> <li><a href="#" id="glubina8">500 ΠΌΠΌ Π Π‘Πš</a></li> <li><a href="#" id="glubina9">550 ΠΌΠΌ Π Π‘Πš</a></li> <li><a href="#" id="glubina10">600 ΠΌΠΌ Π Π‘Πš</a></li> </ul> </div> </div> <div class="dif_box_list dblmarg">Π’ΠΈΠΏ стСклопакСта:<br> <div id="dd3" class="wrapper-dropdown-1" tabindex="1"> <span>ΠžΠ΄Π½ΠΎΠΊΠ°ΠΌΠ΅Ρ€Π½Ρ‹ΠΉ</span> <ul class="dropdown" tabindex="1" style="z-index: 50;"> <li><a href="#" id="steklopaket1">ΠžΠ΄Π½ΠΎΠΊΠ°ΠΌΠ΅Ρ€Π½Ρ‹ΠΉ</a></li> <li><a href="#" id="steklopaket2">Π”Π²ΡƒΡ…ΠΊΠ°ΠΌΠ΅Ρ€Π½Ρ‹ΠΉ</a></li> </ul> </div> </div> <div class="clear"></div> <div class="dif_box_list dblmargleft">Π’ΠΈΠΏ профиля:<br> <div id="dd4" class="wrapper-dropdown-1" tabindex="1" style="z-index: 40;"> <span>- систСмы 58</span> <ul class="dropdown" tabindex="1"> <li><a href="#" id="profil1">- систСмы 58</a></li> <li><a href="#" id="profil2">KBE</a></li> <li><a href="#" id="profil3">REHAU</a></li> <li><a href="#" id="profil4">MONTBLANC ECO</a></li> <li><a href="#" id="profil5">REACHMONT</a></li> <li><a href="#" id="profil6">VEKA</a></li> <li><a href="#" id="profil7">-систСмы 70</a></li> <li><a href="#" id="profil8">KBE</a></li> <li><a href="#" id="profil9">REHAU</a></li> <li><a href="#" id="profil10">VEKA</a></li> </ul> </div> </div> <div class="dif_box_list">Π ΡƒΡ‡ΠΊΠ°:<br> <div id="dd5" class="wrapper-dropdown-1" tabindex="1" style="z-index: 40;"> <span>Π ΡƒΡ‡ΠΊΠ° internika</span> <ul class="dropdown" tabindex="1"> <li><a href="#" id="ruchka1">Π ΡƒΡ‡ΠΊΠ° internika</a></li> <li><a href="#" id="ruchka2">Π ΡƒΡ‡ΠΊΠ° Compact, бСлая</a></li> <li><a href="#" id="ruchka3">Π ΡƒΡ‡ΠΊΠ° Hoppe, бСлая</a></li> </ul> </div> </div> <div class="clear"></div> <div class="dif_box_list dblmargleft">ΠœΠΎΡΠΊΠΈΡ‚Π½Ρ‹Π΅ сСтки: <div class="dbl_check_one"> <input id="check_one" name="set1" type="checkbox" class="checkbox label1"> <label for="check_one" class="label label1">На ΠΎΠΊΠ½ΠΎ</label> <input id="check_two" name="set2" type="checkbox" class="checkbox label2"> <label for="check_two" class="label label2">На Π΄Π²Π΅Ρ€ΡŒ</label> <div class="clear"></div> <input id="check_three" name="set3" type="checkbox" class="checkbox label3"> <label for="check_three" class="label label3">На Π΄Π²Π΅Ρ€ΡŒ</label> </div> </div> <div class="dif_box_list">Π”ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ: <div class="dbl_check_one"> <input id="check_four" name="dopm1" type="checkbox" class="checkbox label4"> <label for="check_four" class="label label4">Π—Π°Ρ‰ΠΈΡ‚Π° ΠΎΡ‚ Π΄Π΅Ρ‚Π΅ΠΉ</label> <div class="clear"></div> <input id="check_five" name="dopm2" type="checkbox" class="checkbox label5"> <label for="check_five" class="label label5">Π ΡƒΡ‡ΠΊΠ° с Π·Π°ΠΌΠΊΠΎΠΌ</label> </div> </div> <div class="calc_refresh"><a class="refresh_link">ΠŸΠΎΠ²Ρ‚ΠΎΡ€ΠΈΡ‚ΡŒ расчСт</a></div> <!-- ***************************** --> <div id="dim"> <div class="window_form"> <div class="close"></div> <div class="delivery_form_title">Π—Π°ΠΏΠΎΠ»Π½ΠΈΡ‚Π΅ Ρ„ΠΎΡ€ΠΌΡƒ для<br>Π·Π°ΠΊΠ°Π·Π° расчСта стоимости</div> <input name="name" type="text" class="delivery_name" placeholder="Π’Π²Π΅Π΄ΠΈΡ‚Π΅ Π’Π°ΡˆΠ΅ имя"><br> <input name="phone" type="text" class="delivery_phone phone3" placeholder="Π’Π²Π΅Π΄ΠΈΡ‚Π΅ Π’Π°Ρˆ Ρ‚Π΅Π»Π΅Ρ„ΠΎΠ½"><br> <input name="email" type="text" class="delivery_email" placeholder="Π’Π²Π΅Π΄ΠΈΡ‚Π΅ Π’Π°ΡˆΡƒ ΠΏΠΎΡ‡Ρ‚Ρƒ"><br> <button>Π Π°ΡΡΡ‡ΠΈΡ‚Π°Ρ‚ΡŒ ΡΡ‚ΠΎΠΈΠΌΠΎΡΡ‚ΡŒ</button> </div> </div> <!-- ***************************** --> </form> 

Js

 function sendForm(form) { var data = { name: $(form).find('input[name="name"]').val(), phone: $(form).find('input[name="phone"]').val(), email: $(form).find('input[name="email"]').val(), wsize1: $(form).find('input[name="wsize1"]').val(), wsize2: $(form).find('input[name="wsize2"]').val(), wsize3: $(form).find('input[name="wsize3"]').val(), wsize4: $(form).find('input[name="wsize4"]').val(), dsize1: $(form).find('input[name="dsize1"]').val(), dsize2: $(form).find('input[name="dsize2"]').val(), type_window: $(form).find('input[name="type_window"]').val(), col_stv: $(form).find('input[name="col_stv"]').val(), stv1: $(form).find('input[name="stv1"]').val(), stv2: $(form).find('input[name="stv2"]').val(), stv3: $(form).find('input[name="stv3"]').val(), furnitura: $(form).find('input[name="furnitura"]').val(), glubina: $(form).find('input[name="glubina"]').val(), steklopaket: $(form).find('input[name="steklopaket"]').val(), profil: $(form).find('input[name="profil"]').val(), ruchka: $(form).find('input[name="ruchka"]').val(), set1: $(form).find('input[name="set1"]').val(), set2: $(form).find('input[name="set2"]').val(), set3: $(form).find('input[name="set3"]').val(), dopm1: $(form).find('input[name="dopm1"]').val(), dopm2: $(form).find('input[name="dopm2"]').val() } switch (form.id) { case 'HeaderForm': data['form'] = 'HeaderForm'; break; case 'DeliveryForm': data['form'] = 'DeliveryForm'; break; case 'ConsultForm': data['form'] = 'ConsultForm'; break; case 'FooterForm': data['form'] = 'FooterForm'; break; case 'CWForm': data['form'] = 'CWForm'; break; case 'CalcForm': data['form'] = 'CalcForm'; break; } $.ajax({ type: 'POST', url: 'mailer.php', data: data, success: function() { $(form).find('input,textarea').each(function(){$(this).val('')}); $("#dim, #dim2").fadeOut('fast', function() { $("#dim3").fadeIn(); setTimeout(function() {$("#dim3").fadeOut();}, 5000); }); } }); } 
  • one
    @Viktor Pavlov, show the code of the form itself and check the values. - VenZell
  • The form code attached in question. There's a lot of HTML in the form. The form is sent by Ajax. - Frontender
  • where is js code then ?? - Artem
  • JS Added - Frontender

1 answer 1

I will not beat around the bush.

But what you have written is a nightmare!

Here everything has been decided for you a long time ago ; you just need to look at how to apply it to your code. It will immediately become more beautiful and will be executed.

// UPD
All because everyone wants to reinvent the wheel !!!

Pastebin to help. Everything works, insert a function, give a link, because it is not difficult to do it as it should. I will not go into details about how many forms you have there and how they work. Here is the ready and working code, which is less at times and more pleasant to view.

Your sendForm (form) did not remove, you can remove it yourself. All json in the console look, everything is transferred there, as needed.

  • Perhaps this is a nightmare, but I do not see any other option. The rest of the fields are sent perfectly. The problem is with the checkbox. - Frontender