I'm trying to check which of four submit buttons was pressed, using jQuery 1.7.2 If any of three of them are clicked, I want to show an alert box with the value of the button. Here is the html code:
<body>
<table>
<tr>
<td>
<input type="submit" id="cancel" value="Cancel">
</td>
</tr>
<tr>
<td>
<input type="submit" id="find" value="Find">
</td>
</tr>
<tr>
<td>
<input type="submit" id="save" value="Save">
</td>
</tr>
<tr>
<td>
<input type="submit" id="update" value="Update">
</td>
</tr>
</table>
</body>
Here is the jQuery function code:
<script>
$(function(){
$(':submit').click(function(){
var value = $(this).val();
//alert(value);
if($(this).val() == "Save" || "Find" || "Clear") {
//if($(this).val() == "Update") {
alert('The value is: ' + value);
}
});
});
</script>
If I click on any of the three buttons I get the value displayed, but if I then click on the Update button it is also displayed. I thought my if block would prevent that from happening?
If I comment out that line and use this code instead:
if($(this).val() == "Update") {
alert('The value is: ' + value);
}
Then only when I click on the Update button will the alert fire. What is wrong with the code here when I'm checking for multiple submit buttons?