There are some situation when we need to fire only one event on Enter key and block others default event like a button.
Suppose we have a search box and that is available on all page through master page, In this condition where ever other button would be there we can face default event problem. So preventing this situation we can use preventDefault(); ...
This is one code that can help u to understand this situation and u can get solution.
Here I bind a keypress event to one text box that id is txtUserName.
$('#txtUserName').bind('keypress', function(e)
{
if(e.keyCode==13){
if($("#txtUserName").attr("value")=="")
{
alert("please enter value to search");
}
else
{
e.preventDefault();
location.href=getSPUrl() +"Search/Pages/results.aspx?k=" + $("#txtUserName").attr("value");
}
}
});
I think your looking for this only;...
Thanks and Regards,
Shailendra Kumar Singh
No comments:
Post a Comment