0

I have a form with button A and button B. It's sent by a jQuery function called clicking on one of the buttons. At the end of this long function which is checking prerequisites, the form is sent using this line:

$('#wlform').submit();

I want to adjust this code to send something to be able to distinguish which button was pressed. Something in JavaScript similar to <input type="submit" name="submitbutton1"/>

Rápli András
  • 3,869
  • 1
  • 35
  • 55

4 Answers4

0

Just give to the hidden input the value of the button id attribute. You could do something similar to this (before the submit statement):

$('input[type=hidden]').val($(this).attr('id'));

Where $(this) is the button clicked.

Eduardo Casas
  • 578
  • 4
  • 11
0

Provide us with some code?

I think you're talking about two buttons that both should have their own ID's. You could try and catch the ID attributes after you click them;

$(this).attr('id');

Or change 'id' into 'name' if you want to get that value.

BBQ.
  • 169
  • 11
0

I suppose you use a javascrit click event to execute your javascript functions.

In javascript, you can add a hidden input to your form :

$(...).click(function() {
    ... // Your code

    var clicked_button = $(this);
    $('#wlform').append($('<input type="hidden" name="clicked-button"/>').val(clicked_button.attr('id'));

    $('#wlform').submit();
});

With that, the id of the clicked_button will be sent with the form.

Magus
  • 14,796
  • 3
  • 36
  • 51
0

None of the answers worked, so I've put something together from these on my own. I've added a hidden input field, clicked-button as you suggested. Then when calling my precheck_submit function, I pass another parameter (c) for storing which has been clicked. In the precheck_submit function I added $('#clicked-button').val(c);. It works. Anyways, thanks for your efforts.

Rápli András
  • 3,869
  • 1
  • 35
  • 55