This code is working fine but the problem with code is that it disable enter key functionality in multiline textbox of asp.net. Your above mention code is disabling enter key on textbox.
But I need to enable only on textbox but disable on form in order to save from submit.
change test to:
if (e.which == 13 && e.delegateTarget.tagName != 'TEXTAREA')
Hi bruce,
Thanks for your advise but it is not disable enter key on form submit. After again searching on jQuery.com, I found another attribute similar to delegateTarget. After using that attribute, my form is in working perfectly.
matifnadeem
Contributor
4580 Points
1090 Posts
Disable Enter Key for Submit form excluding multiline textbox
Dec 31, 2012 09:41 AM|LINK
Hi all,
I am try to disable enter key only for form submit but suddenly I realized that my multiline textbox is not working because Enter key is disable.
My code is
ASPX MARKUP : --------------- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript"> $(document).keypress(function(e) { if (e.which == 13) { return false; } }); </script> <asp:TextBox ID="MultilineTextBox" runat="server" TextMode="MultiLine" />I found similar thread on Asp.net forum too but that not working here.
Another important link also unable to integrate after modification
Share your ideas how to do this?
M Atif Nadeem
Mark as Answer if you got right thing
Read my blog | Follow me on LinkedIn
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Disable Enter Key for Submit form excluding multiline textbox
Dec 31, 2012 10:37 AM|LINK
This way
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript"> $("input[type=text]").live("keypress", function(e) { if (e.which == 13) { return false; } }); </script>Contact me
matifnadeem
Contributor
4580 Points
1090 Posts
Re: Disable Enter Key for Submit form excluding multiline textbox
Dec 31, 2012 11:53 AM|LINK
Hi mudassarkhan,
I am using this code to disable enter key on page because when user hit enter key, form will be submitted.
$(document).keypress(function(e) { if (e.which == 13) { return false; } });This code is working fine but the problem with code is that it disable enter key functionality in multiline textbox of asp.net. Your above mention code is disabling enter key on textbox.
But I need to enable only on textbox but disable on form in order to save from submit.
Cheers
M Atif Nadeem
Mark as Answer if you got right thing
Read my blog | Follow me on LinkedIn
bruce (sqlwo...
All-Star
36644 Points
5432 Posts
Re: Disable Enter Key for Submit form excluding multiline textbox
Dec 31, 2012 10:10 PM|LINK
change test to:
matifnadeem
Contributor
4580 Points
1090 Posts
Re: Disable Enter Key for Submit form excluding multiline textbox
Jan 01, 2013 05:37 AM|LINK
Hi bruce,
Thanks for your advise but it is not disable enter key on form submit. After again searching on jQuery.com, I found another attribute similar to delegateTarget. After using that attribute, my form is in working perfectly.
I wanna share code with all of you
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript"> $(document).keypress(function(e) { if (e.which == 13 && e.target.tagName != 'TEXTAREA') { return false; } }); </script>Using above jQuery code, it will disable enter key hitting on form but it allow multitext TextBox like Asp.net TextBox to hit enter key within it.
Cheers
M Atif Nadeem
Mark as Answer if you got right thing
Read my blog | Follow me on LinkedIn