I'm using jQuery to show/hide a div
by clicking on the show/hide buttons. However, my code doesn't work because every time it returns to the way it was before when I click on my buttons. I'm almost sure that this is due to a page reload, because every time I click on a button it reloads the page.
Does anybody know what could be the reason behind this?
Here is the important chunk of code:
<form role="form" method="post" action="./something.php">
...
<button id="hidemultmachines" onclick="$('#multmachines').hide(); $(this).hide(); $('#showmultmachines').show();">
Hide section below ...
</button>
<button id="showmultmachines" onclick="$('#multmachines').show(); $(this).hide(); $('#hidemultmachines').show();">
... Create multiple entries
</button>
<div id="multmachines">
...
</div>
<div>
<div>
<input type="hidden" name="total" value="{ $smarty.section.i.total }">
<button type="submit" name="Submit" value="Save">Save</button>
</div>
</div>
</form>
And this is my jQuery code in the header:
$(document).ready(function(){
$('#hidemultmachines').hide();
$('#multmachines').hide();
}
When I put the buttons outside the form it works. Why?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…