Showing posts with the label Jquery

Log exception to file in c# .net core application explained

In production environment when any bug gets reported at that time as developer wants to get the exception details of bug to resolve the issue on high priority.
In some case there might be situation where exception is not logged in table but developer wants to check the bug immediately. for that purpose we need to write the
exception details including stack trace of bug in file. To implement this easily i am going to demonstrate the implementation of custom logging in file as below.

First we need to construct the exception and logger method in custom logger class as shown below.

public class CustomLogger { public static List<string> ConstructExceptionDetails(Exception ex,string FunctionName) { return new List<string>() { $"{DateTime.Now} - {FunctionName}", $"Exception: {ex.Message}", $"StackTrace: {ex.StackTrace}", $"InnerException: {ex.InnerException?.…

Email validation using regular expression in jQuery

To validate user input for email-id it's very easy using regular expressions. Using regular expressions you do not need to write lengthy logical code in jQuery. Following are the steps to do the same.

Pass a string to RegExp or create a regex using the //syntaxCall regex.test(string) So code would be... jQuery(function(){ $(".mail").keyup(function(){var VAL =

Numeric validation on textbox/input on keydown event using JQuery

This is simple way to implement the numeric validation on textbox or input control using jquery. Firstly you need to use jquery selector for binding the keydown event to input control. Once you bind it it will only allow numeric keys and reject the alphabetical keys. Following is the code snippet of the numeric validation using Jquery.

$(document).ready(function () { $("#MobileNo").keydown(function (e) { // Allow: backspace, delete, tab, escape, enter and . if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 || // Allow: Ctrl+A (e.keyCode == 65 && e.ctrlKey === true) || // Allow: home, end, left, right, down, up (e.keyCode >= 35 && e.keyCode <= 40)) { // let it happen, don't do anything return; } // Ensure that it is a number and stop the keypress if ((e.shiftKey || (e.keyCode < 48 || e.keyC…

Populate Dropdown with jquery using JSON request in mvc3

In this Article i am going to demonstrate to fill the dropdownlist with jquery using JSON in mvc3. To achieve this task we need to write the following JavaScript code in view (.cshtml page)

@{ ViewBag.Title = "Products"; } <script type="text/javascript"> jquery(document).ready(function () { jquery("ddlCategory").change(function () { var idModel = jquery("#ddlCategory").val(); jquery.getJSON("product/items/", { category: idModel }, function (carData) { var select =jquery("#ddlitems"); select.empty(); select.append($('<option/>', { value: 0, text: "" })); jquery.each(carData, function (index, itemData) { …

Creation of Date Format function using javascript and Jquery

If you want to format the datetime string of database in your html file you need to get help from javascript.In javascript there is no pre define function exists to format date time string in dd MMM yyy. To accomplish the above task you need to write custom code. The following  is the custom function by using that you can format your datetime string in dd MMM yyyy format

first you need to write array which has all months

var gsMonthNames = new Array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' );
Then add following function in html file

function dFormat(date) { var result = ''; if (date != '') { var dateArray = date.split('/'); if (dateArray.length > 1) { result = dateArray[1] + " " + gsMonthNames[parseInt(dateArray[0])-1] + " " + …

Disable backspace key using Jquery

Disable backspace key in HTML form using Jquery in simple steps.

While user enters data into application if user accidentally press backspace button then it will redirect to previous page and all entered data would be lost. to eliminate this event we can disable the backspace key using Jquery.

Following is the JQuery script tag you can add to the web page
$(document).keydown(function (e) { var nodeName =; if (e.which === 8) { if ((nodeName === 'input' && === 'text') || nodeName === 'textarea') { // do nothing } else { e.preventDefault(); } } });
The above code can be used seamlessly with any web technology you are using. Hope this will help you in your web application.

Happy coding:)

Get value of dropdownlist or html select using Jquery

In Jquery code you need to write one line code to get value of dropdownlist. You can use following code to get value of selected option
Var selectvalue=$('#urid').val();
You can use following code to get text of selected option
Var selecttext=$('#urid').text();
Ur done...... Happy Jquering ,...........

Enable disable all buttons of html form using Jquery

To enable disable all the buttons of html form needs to write lots of code in javascript. In javascript first we need to find all input elements which having input type submit and store it in array. After storing elements in array needs to loop that array and disable or enable element one by one. Instead of writing lots of code we can use Jquery one line code as follows
The above Jquery code will disable all input elements which having type submit.

Happy Jquering................