Skip to main content

Get text from textbox on enter key press using jQuery.

1. Add Jquery on page.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>

2. Add HTML textarea.
    <textarea id="txtcomment" placeholder="Type your comment here and press Enter Key...."></textarea>

3. add script after text area.
 <script type="text/javascript">
 $('#txtcomment').keypress(function (event) {

                var keycode = (event.keyCode ? event.keyCode : event.which);
                if (keycode == '13') {
                    alert($('#txtcomment').val());
                    savecomment($('#hdnBlogid').val(), $('#txtcomment').val());
                }
                event.stopPropagation();
            });

   </script>
4. run the html page and type in textbox when you press enter that time you can see one alert box with textbox value.

Comments

Popular posts from this blog

How to write Unit Tests in .net

Unit tests are automated tests that verify the behavior code like methods and functions. Writing unit tests is crucial to clean coding, as they help ensure your code works as intended and catches bugs early in the development process. I can share some tips for writing effective unit tests: Write tests for all public methods Every public method in your code should have a corresponding unit test. This helps ensure that your code behaves correctly and catches any unexpected behavior early. public class Calculator { public int Add(int a, int b) { return a + b; } } [TestClass] public class CalculatorTests { [TestMethod] public void Add_ShouldReturnCorrectSum() { // Arrange Calculator calculator = new Calculator(); int a = 1; int b = 2; // Act int result = calculator.Add(a, b); // Assert Assert.AreEqual(3, result); } } Test boundary conditions  Make sure to test boundary conditions, such a...

How To Implement NLog With WebAPI In Asp.Net(C#).

What is NLog? NLog is a flexible and free logging platform for various .NET platforms, including .NET standard. NLog is easy to apply and it includes several targets (database, file, event viewer). Which platform support it? .NET Framework 3.5, 4, 4.5, 4.6 & 4.7 .NET Framework 4 client profile Xamarin Android Xamarin iOS Windows Phone 8 Silver light 4 and 5 Mono 4 ASP.NET 4 (NLog.Web package) ASP.NET Core (NLog.Web.AspNetCore package) .NET Core (NLog.Extensions.Logging package) .NET Standard 1.x - NLog 4.5 .NET Standard 2.x - NLog 4.5 UWP - NLog 4.5 There are several log levels. Fatal : Something terrible occurred; the application is going down  Error : Something fizzled; the application might possibly proceed Warn : Something surprising; the application will proceed  Info : Normal conduct like mail sent, client refreshed profile and so on.  Debug : For troubleshooting; the executed question, the client confirmed, ...

How to Manage State in .NET Core

 In any application development, managing state effectively is crucial for maintaining data consistency and providing a seamless user experience. In .NET Core, various techniques and libraries are available for managing state, each catering to different scenarios and requirements. This article explores different state management techniques in .NET Core and provides code examples to illustrate their usage. Built-in State Management Techniques Session State : Session state allows storing user-specific data across multiple requests. It's useful for maintaining user authentication, shopping cart items, etc. Session state can be managed using ASP.NET Core's HttpContext.Session property. // Setting session value HttpContext.Session.SetString("UserName", "JohnDoe"); // Retrieving session value var userName = HttpContext.Session.GetString("UserName"); View State: View state stores page-specific data that needs to be persisted across postbacks. It'...