There is an input field, which, depending on the selected settings, performs either the function of adding to the database or searching the database with the specified mask.
The form itself:

<form method="post"> <p>Ѐамилия участника : <p><input id="new_partner" name="name_partner" type="text" placeholder="Ѐамилия"> <p> Π Π΅ΠΆΠΈΠΌ Ρ€Π°Π±ΠΎΡ‚Ρ‹: <p><input id="check" name="option1" type="radio"> Π”ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ Π½ΠΎΠ²ΠΎΠ³ΠΎ участника <input id="check" name="option2" type="radio"> Поиск участника ΠΏΠΎ ΡƒΠΊΠ°Π·Π°Π½Π½ΠΎΠΉ маскС <div id="link" hidden> <p>Π”ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ настройки: <p><input id="check" name="option3" type="checkbox"> Автосортировка Ρ‚Π°Π±Π»ΠΈΡ†Ρ‹ участников </div> <p><input type="submit" name="submit" value="Π’Ρ‹ΠΏΠΎΠ»Π½ΠΈΡ‚ΡŒ" > <input type="submit" name="submit" value="ΠŸΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ вСсь список участников" > </form> 

How to check the selected radio input settings using ajax, so that when you select the "Search for a participant by the specified mask" option, the script will run below?

The script that performs the search with the specified condition (registered for another input):

 $(function() { $("#search").keyup(function(){ var search = $("#search").val(); $.ajax({ type: "POST", url: "/action", data: {"search": search}, cache: false, success: function(response){ $("#resSearch").html(response); } }); return false; }); }); 

    1 answer 1

    Add radiobutton's value to html, and the name should be the same for them:

     <input id="check" name="optionRadio" value="1" type="radio"> Π”ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ Π½ΠΎΠ²ΠΎΠ³ΠΎ участника <input id="check" name="optionRadio" value="2" type="radio"> Поиск участника ΠΏΠΎ ΡƒΠΊΠ°Π·Π°Π½Π½ΠΎΠΉ маскС 

    Now you need to get the value from the selected button in the mode of switching them:

     $('input[name=optionRadio]').change(function() { var value = $('input[name=optionRadio]:checked').val(); }); 

    And further, based on the obtained value, build your own button behavior logic. Example