Single jQuery POST with multiple buttons and responsive actions


username

I am sending the same POST value multiple times. Is it possible to just set the POST value once and then use it multiple times with different buttons?

Example: Complete code:

  $('#btn1').click(function(){   
        $.post("my.php",
            {
              status:$('input[name=radio]:checked').val(),
              name:$( '#name' ).val(),
              subject:$( '#subject' ).val()
            },
          function(response) {
            //do something with response...
          });
  });

I want to do something like this:

function getPost(){
   $.post("my.php",
   {
     status:$('input[name=radio]:checked').val(),
     name:$( '#name' ).val(),
     subject:$( '#subject' ).val()
     },
}

      $('#btn1').click(function(){   
            getPost();
              function(response) {
                //do AAAAA...
              });
      });

      $('#btn2').click(function(){   
            getPost();
              function(response) {
                //do BBBBB...
              });
      });
Gerald Eastar

Something like this might be

function getData(){
  return {
     status:$('input[name=radio]:checked').val(),
     name:$( '#name' ).val(),
     subject:$( '#subject' ).val()
    }
}

$('#btn1').click(function(){   
  $.post(url, getData(), function( response ){ /* do AAA with respone */ });
});

$('#btn2').click(function(){   
  $.post(url, getData(), function( response ){ /* do BBB with response */ });
});

Related


jQuery context menu, single menu with multiple actions

John I am using the following jQuery context menu: http://www.javascripttoolbox.com/lib/contextmenu/index.php Usage is very simple as you can create a menu like this var menu1 = [ {'Option 1':function(menuItem,menu) { alert("You clicked Option 1!"); } }, $

Make buttons in v-card-actions responsive

Twilight I have a v-cardbutton with three buttons ( ) v-btn, v-card-actionseach with a long text on it. This is basically fine, but when viewed on a small screen, the buttons are unresponsive, they are still aligned left to right instead of top to bottom, so t

Multiple actions on a single event

Raffin Weller Trying to get one event to trigger multiple switchMaps with initial event data. Each operation creates a promise to some transformation, which is then written to the filesystem. These actions are independent and unrelated, but use the same data f

Multiple actions on a single event

Raffin Weller Trying to get one event to trigger multiple switchMaps with initial event data. Each operation creates a promise to some transformation, which is then written to the filesystem. These actions are independent and unrelated, but use the same data f

Multiple buttons to perform multiple actions without IB

blue turtle In my view controller I have 10 buttons. Each button has a label and all buttons call the same action (separated by a switch (sender.tag), case 0 -> case 9 to distinguish which button is selected). I made it in IB, connected all the buttons ( ) @IB

Multiple buttons to perform multiple actions without IB

blue turtle In my view controller I have 10 buttons. Each button has a label and all buttons call the same action (separated by a switch (sender.tag), case 0 -> case 9 to distinguish which button is selected). I made it in IB, connected all the buttons ( ) @IB

GitHub Actions Multiple Actions in a Single Repository

Dusans Mannix I have an application code in a Github repository and I want to customize some stages of my pipeline and want to write my own custom actions (in a private repository), since these custom actions have to be placed in the action Can I save multiple

Post submit with radio buttons with different actions

Takeov3r I want to send information using POST (not GET) I have a list of 50 items, each with two icons (radio buttons): item 1 <label style='cursor: pointer;'> <input type='radio' name='video' id='video' value='123ASD'/> <img src='mp4-icon.png' width='20' ali

Post submit with radio buttons with different actions

Takeov3r I want to send information using POST (not GET) I have a list of 50 items, each with two icons (radio buttons): item 1 <label style='cursor: pointer;'> <input type='radio' name='video' id='video' value='123ASD'/> <img src='mp4-icon.png' width='20' ali

NGRX - Multiple actions on a single effect

vocal This is my effect. @Effect() uploadImages$ = this.actions$ .ofType(ProjectActions.UPLOAD_IMAGES) .map(action => action.payload) .flatMap(project => this.service.uploadImages(project)) .switchMap((project) => Observable.of( this.imageActio

NGRX - Multiple actions on a single effect

vocal This is my effect. @Effect() uploadImages$ = this.actions$ .ofType(ProjectActions.UPLOAD_IMAGES) .map(action => action.payload) .flatMap(project => this.service.uploadImages(project)) .switchMap((project) => Observable.of( this.imageActio

Multiple submit buttons with different actions passing variables

Pasha I have a form like the code below (called index.php) with multiple submit buttons. I want to do different php actions on submit button. The first button, no need to refresh the browser page, and certainly no need to refresh the variables. The other has n

Multiple update buttons on a single form

fired Please excuse my horrible structured code. I am trying to update each row of different customers with separate submit buttons. The delete function works great. When the submit button for each row is clicked, I am trying to pass the ID of that row. Howeve

Use multiple buttons in a single activity

Jekor I have 56 toggle buttons and 8 regular buttons in a single activity. The 8 buttons are not a problem because I'm using a single onClickListener class with a toggle box that determines what each button does. The problem is with the 56 toggle buttons. I kn

Use multiple buttons in a single activity

Jekor I have 56 toggle buttons and 8 regular buttons in a single activity. The 8 buttons are not a problem because I'm using a single onClickListener class with a toggle box that determines what each button does. The problem is with the 56 toggle buttons. I kn

Single action listener for multiple buttons

Maitri Patel Can anyone help me how to add a single action listener on multiple buttons ? Here is my multi-action listener code for multiple buttons. I also tried to use a generic button as an action listener for all buttons. Can anyone suggest me a related an

Control multiple buttons with a single button

ford harrison I have created 10 different buttons, each button has a unique SUB() assigned to it. Now I want to execute all 10 buttons with one click of the main button. Is that possible? Can someone guide me? username Assuming your "Master" button is named "M

jQuery for multiple buttons and divs

Vinicius Martinson I'm having some trouble making a button that shows only one div instead of all divs. Here is my JS code: $('.show_avatar').click(function(){ $('.avatar').toggle('slow',function() { }); }); Here is my HTML: <input class="show_avatar" typ

jQuery for multiple buttons and divs

Vinicius Martinson I'm having some trouble making a button that shows only one div instead of all divs. Here is my JS code: $('.show_avatar').click(function(){ $('.avatar').toggle('slow',function() { }); }); Here is my HTML: <input class="show_avatar" typ

Put multiple responsive images into a single div with CSS

salmonella I want to create this type of structure with images. I'm using bootstrap, is it possible to create this type of layout using bootstrap, if not, how? Here is sample code: .side_padding { padding-left: 2.5%; padding-right: 2.5%; } .img_holder { object