Problem:
To detect with jQuery which submit button was pressed after the form is sent through PHP.
Scenario:
I have three buttons:
- submit-update1
- submit-update2
- submit-update3
If $_POST['submit-update1'] is set in PHP then jQuery should add a class to a div with id "collapseOne". For instance:
if (PHP POST submit button 1 is submitted)
{
$('#collapseOne').addClass('in');
}
if (PHP POST submit button 2 is submitted)
{
$('#collapseTwo').addClass('in');
}
if (PHP POST submit button 3 is submitted)
{
$('#collapseThree').addClass('in');
}
DIV elements:
<div class="accordion" id="accordion2">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
Title 1
</a>
</div>
<div id="collapseOne" class="accordion-body collapse">
<div class="accordion-inner">
Text here
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
Title 2
</a>
</div>
<div id="collapseTwo" class="accordion-body collapse">
<div class="accordion-inner">
Text here
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseThree">
Title 3
</a>
</div>
<div id="collapseThree" class="accordion-body collapse">
<div class="accordion-inner">
Text here
</div>
</div>
</div>
</div>
Submit buttons:
<button type="submit" id="submit-update1" name="submit-update1">Update 1</button>
<button type="submit" id="submit-update2" name="submit-update2">Update 2</button>
<button type="submit" id="submit-update3" name="submit-update3">Update 3</button>
Any advice is welcome and thanks in advance!