Programming Time

Articles for your daily pleasure.

Auto select menu using jQuery

Hello guys, today we’ll learn about How we can auto select menu using Jquery.

The most common functionality in almost all websites is that to show selected menu which was previously clicked. There are many ways to do this, either we can achieve this using server side language or we can use jQuery or javascript(Almost all browsers supports javascript by default). So its up to us, how we want to integrate this.

I will use jQuery  and almost each website use this for having image slider, hierarchical dropdown etc which not possible without using jQuery.

So let’s start doing code, before coding let’s think, how we can do this.

The Idea, I am using is very simple, what I will do, I will get the page name from the browser URL and compare with each menu. isn’t simple?


On page load I will call one function that will get page name from URL and one by one it will compare that page name with each menu and if menu matches with page name then we can add class that is responsible to add styles to make menu look like selected, following is the code that will auto select the menu item.

 $(function () {

            var url = document.location.href;
            var page = url.substring(url.lastIndexOf('/') + 1).toLowerCase();
            $(".left-navigation li").each(function () {

                var href = $(this).find("a").attr("href");
                var menuUrl = href.substring(href.lastIndexOf('/') + 1).toLowerCase();
                if (page == menuUrl) {


Some Useful Jquery Stuff

Hello World in this post,  I will share Some Useful Jquery Stuff that could be helpful for developing  any web application.

When we make a web application, then we have to manage two things (functionality and cool UI). User Interface is very important part for each application, so that each functionality of website could be accessed by user easily.

So in order to achieve this, fortunately, we have some tools available on Internet which are really helpful for any web application are as follows:

1.  Animate Css

Animate Css is a bunch of cool, beautiful, and cross-browser animations for your projects. Great for emphasis, home pages, sliders, and general just-add-water-awesomeness.
Demo & Download


2.  Masked Input Plugin

This is a masked input plugin for the jQuery javascript library. It allows a user to more easily enter fixed width input where you would like them to enter the data in a certain format (dates,phone numbers, etc). You could choose according to your needs.
Demo & Download


3.  jQuery Countdown

A jQuery plugin that uses a div or span to show a countdown to a given time. There are formats and layout available for customization, so could be manage to use according to your needs and they have very good document this helps user to setup without any hassle. You can check more feature and information on their site using below link.
Demo & Download


4.  Switchery

So what actually Switchery does, it converts the simple html checkbox input into beautiful iOs 7 style switches in just few simple steps. You can easily setup Switchery into your website. You can easily customize any Switches according to your requirements like you can set any color you want and they also have very well documentation on their site so you can check all information using below link.
Demo & Download


5.  jQuery Print Page Plugins

If you want print functionality on your website and your requirement to show particular section in print preview window with style modifications, then these plugins may help you. Wondering how yow can use these?, here is complete information, enjoy!
Demo & Download


6.  jQuery Mask Plugin

A jQuery Plugin to make masks on form fields and HTML elements. The main difference is if we compare this plugin with other is that this plugin does not place mask before entering any value.
And other good feature is, if you have un-masked value being displayed on the page then you also put format on it without any hassle. This plugin does support masking to almost all fields like date, phone number etc.
Demo & Download

Many more, will be added in future, stay tuned.

How to update path in table column using SQL

Today in this post we will discuss about How to update path in table column using SQL

When we need to do this

Sometimes, we save path of any file in database, assume that all files being saved in D drive but later you don’t want to save your files on D drive, maybe you need to switch your host and their D drive not available. There might be many cases when we need to change the path.

Now question is how we can easily change the file path using sql command, its very simple I will show you how.

In my query I am updating path from D drive to G drive, you can assume that the paths are saved in table all belongs to the drive D. Now we will update all our paths by using simple sql query.

Update TableName set 
FilePath = 'G' + SUBSTRING (LTRIM(FilePath), 2, LEN(FilePath)),
Where FilePath like 'D%'

In above sql query I am using ‘SUBSTRING’ function of MSSQL server, which takes three param,  first param where to find the string, second one is Index like from where you want to get the text like in above example I am getting value from second index not first and third parameter tells count to sql  means how many chars need to include after starting from index.

Things to remember

Normally index starts from 0 but in sql it will start from 1, so adjust your query accordingly and you may also noticed that why I am using LTRIM what is the use of this sql function?

Sometime accidentally we inserts some empty spaces why programming language or manually insertion. You should check the paths carefully if your path contains empty spaces then you should use LTRIM sql method this function is used to remove spaces from the string

After that you might also noticed that we are only getting those records where path starting from letter D, we don’t need any other records we only want to change the path of drive D.

Hope you will like this, please forget to share your thoughts

Easy way to remove special characters from string

In this post we will learn about Easy way to remove special characters from string. There are many ways available to achieve this like we can use string.replace method we can also use regex and many more but there should be a simple c# method that should take care about this

In this example I will show how we can create our custom method to replace special characters and plus point is we can add as many chars as we can which we don’t want to see in our string
So here we go, I will use linq in order to achieve this. Linq is fast and makes your life easy

public static string RemoveSpecialChars(string requestedString)
           if (string.IsNullOrEmpty(requestedString))
               return requestedString;

           var symbols = new[] { ",", ".", "/", "!", "@", "$", "%", "^", "&", "*", "'", "\"", ";", "_", "(", ")", ":", "|", "[", "]" }; 
           return symbols.Aggregate(requestedString, (current, symbol) => current.Contains(symbol) ? current.Replace(symbol, String.Empty) : current);

Benefits of Custom Method

There are many benefits of  custom extension method that will allow you add your desired chars to exclude from string or you can also customize this method according to your needs and we’re using linq so its fast.

Hope you enjoyed it.

Page 1 of 6

© 2016 All Right Reserved. & Powered by WordPress & Privacy Policy