Reputation: 171
This should be a simple question, but I am new to JQuery.
The code below will execute when a textbox with ID="CompanyName" entered. I have another textbox with ID="City". How can I put and OR statement, saying that "Either CompanyName or City boxes enter, process the same code below.
Thanks,
$('#CompanyName').on('keypress', function(e) {
if (e.keyCode == 13)
{
//alert("Found");
e.preventDefault();
// Some code here.....
}
});
Upvotes: 0
Views: 48
Reputation: 8457
$("#CompanyName, #City").change(function() {
//alert ("Found);
.........
execute code
.........
)};
Upvotes: 1
Reputation: 22031
Try to specify multiple selectors, separated by ","
$('#CompanyName, #City').on('keypre..
This should fix your issue
Upvotes: 2
Reputation: 305
You could try giving them a common class, and selecting that instead, eg
$('.class-name').on('keypress', function(e) {
Upvotes: 2