Category Archives: JavaScript

Method Chaining in Javascript

Method chaining is a technique that can be used to simplify code in scenarios that involve calling multiple functions on the same object consecutively. This chain is just a single expression. It’s easy enough to break this chain down and make each of the calls into separate expressions, but then it would obviously not be… Read More »

How to get Value from usercontrol to aspx page in Javascript

In this post i will show how to get value of a textbox of user control in Asp.net page where that user control is registered.This question is asked in my many interview so come to the example lets first create a user control with the name of Test.  <%@ Control Language=”C#” AutoEventWireup=”true” CodeFile=”Test.ascx.cs” Inherits=”Test” %>… Read More »

Clear JS and CSS cache in jQuery

You can’t clear client system browser cache using jQuery or javascript but you can clear your application cache pragmatically. $(‘.button’).click(function() { $.ajax({ url: “”, context: document.body, success: function(s,x){ $(‘html[manifest=saveappoffline.appcache]’).attr(‘content’, ”); $(this).html(s); } }); }); or you have to disable the cache control <meta http-equiv=’cache-control’ content=’no-cache’> <meta http-equiv=’expires’ content=’0′> <meta http-equiv=’pragma’ content=’no-cache’>

JavaScript closures

JavaScript variables can belong to the local or global scope where as Private variables can be made possible with closures. A closure is an inner function that has access to the outer (enclosing) function’s variables—scope chain. The closure has three scope chains: it has access to its own scope (variables defined between its curly brackets),… Read More »

Disable Cut Copy Paste operation using jQuery

Somtimes we need to disable Cut, Copy, Paste content from textbox in our site due to some reasons(like don’t allow to copy password from password TextBox to Confirm password TextBox). We can implement this functionality with the help of below example. First create two textboxes control  password and  confirm password. <table> <tr><td>Password: </td><td><asp:TextBox ID=”txtPassword” runat=”server”></asp:TextBox></td></tr>… Read More »

Check whether a CheckBox is checked or not

Here I will show how to Check whether a CheckBox is checked or not with example. Check whether a CheckBox is checked (selected) or not using jQuery <script type=”text/javascript”> $(function () { $(“#btnCheck”).click(function () { var isChecked = $(“#chkbox”).is(“:checked”); if (isChecked) { alert(“CheckBox checked.”); } else { alert(“CheckBox not checked.”); } }); }); </script>

Radio button is check or not

Here I will show how to Check whether radio button is check or not with example. Radio button is check or not    <script type=”text/javascript”> function call() { var jq = jQuery.noConflict(); var rd = jq(“#s1”).is(‘:checked’); //.val(); alert(rd); } </script>

Special characters in javascript

function chkSpecialChars_citynu(input) { var iChars = “!@$%^&*()+=[];{}|<>?”; for (var i = 0; i < input.length; i++) { if (iChars.indexOf(input.charAt(i)) != -1) { return false; } } return true; }

create objects in JavaScript

There are 3 ways to create object in JavaScript. By object literal By creating instance of Object By Object Constructor Examples object using object literal object={property1:value1,property2:value2…..propertyN:valueN} creating object in JavaScript emp={id:102,name:”Amit Kumar”,salary:19000} document.write(emp.id+” “+emp.name+” “+emp.salary);