I use mutliple framesets on a page, and each frameset has an associated button to perform a server/client side postback. I wanted to change the default enter key to select the correct button and this was my soltuion using jQuery.
$("#<%= SearchCustomers.ClientID %>").find(":input").click(function() { $(this).parents("FIELDSET").addClass("default"); }).blur(function() { $(this).parents("FIELDSET").removeClass("default"); });
$("#<%= SearchGroups.ClientID %>").find(":input").click(function() { $(this).parents("FIELDSET").addClass("default"); }).blur(function() { $(this).parents("FIELDSET").removeClass("default"); });
$(document).keypress(function(e) {
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
$(".default").find(":submit,:button").click();
return false;
}
});
This is working perfect, but I was looking for ways to improve this. Right now, the code is dependent on me setting the framesets to "runat=server" so I can access the "ClientID" property and inject the ID into my javascript. This makes the code a little less re-usable, so I was curious if somebody else had a better idea...
Thanks for your comments!