Home ajax Processing INPUT RADIO

Processing INPUT RADIO

Author

Date

Category

There is an Input field, which, depending on the selected settings, either the adding function to the database or the search for the database with the specified mask.
Form:

& lt; form method = "post" & gt;
    & lt; p & gt; Member last name:
    & lt; p & gt; & lt; input id = "new_partner" name = "name_partner" type = "text" placeholder = "surname" & gt;
    & lt; p & gt; Mode of operation:
      & lt; p & gt; & lt; input id = "Check" name = "option1" type = "Radio" & gt; Adding a new member
        & lt; input id = "Check" name = "option2" type = "Radio" & gt; Search for a member by specified mask
     & lt; div id = "link" hidden & gt;
      & lt; p & gt; Additional settings:
      & lt; p & gt; & lt; input id = "Check" name = "option3" type = "checkbox" & gt; Autodist Table Participants
     & lt; / div & gt;
    & lt; p & gt; & lt; input type = "submit" name = "submit" Value = "Run" & gt;
      & lt; input type = "submit" name = "submit" value = "View the entire list of participants" & gt;
  & lt; / form & gt;

How to use AJAX to check the selected RADIO INPUT settings so that when selecting the “Search for the Participant Mask” item, the script launched below?

Script, which makes a 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) {
        $ ("# rasearch"). HTML (Response);
      }
    });
    RETURN FALSE;
  });
});

Answer 1, Authority 100%

Add to HTML Values ​​Value RadioButton’ov, and Name should be the same with them:

& lt; input id = "check" name = "optionradio" value = "1" type = "Radio" & gt; Adding a new member
& lt; input id = "Check" name = "optionradio" value = "2" type = "Radio" & gt; Search for a member by specified mask

Now you need to get Value from the selected button’a in switching them:

$ ('input [name = optionradio]). Change (Function () {
   var value = $ ('INPUT [NAME = OptionRadio]: Checked'). Val ();
});

And then, based on the value, build your button behavior logic. Example

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions