Friday, 29 March 2013

javascript maintain page scroll position

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
 <title>Test Page</title>
 <script type="text/javascript">
 function callTest(value)
 {
   alert(value);
 }
 </script>
</head>

<body>
 <form id="form1" runat="server">
  <table>
   <tr>
    <td style="height: 300px;">
     <a href="javascript:void(0);" id="A1" onclick="javascript:callTest('Add');" >Add</a>
     <p> Description 1............</p>
    </td>
   </tr>
   <tr>
    <td style="height: 300px;">
     <a href="javascript:void(0);" id="A2" onclick="javascript:callTest('Edit');" >Edit</a>
     <p> Description 2............</p>
    </td>
   </tr>
   <tr>
    <td style="height: 300px;">
     <a href="javascript:void(0);" id="A3" onclick="javascript:callTest('Delete');" >Delete</a>
     <p> Description 3............</p>
    </td>
   </tr>
   <tr>
    <td style="height: 300px;">
     <a href="javascript:void(0);" id="A4" onclick="javascript:callTest('View');" >View</a>
     <p> Description 4............</p>
    </td>
   </tr>
  </table>
 </form>
</body>
</html>

Get Page Name In Javascript ??

  <script type="text/javascript">

        var sPath = window.location.pathname;
       var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
       alert(sPage);

</script>

Thursday, 28 March 2013

Get Cookie Value From Javascript ??

function getCookie(cookiename)
  {
  // Get name followed by anything except a semicolon
  var cookiestring=RegExp(""+cookiename+"[^;]+").exec(document.cookie);
  // Return everything after the equal sign
  return unescape(!!cookiestring ? cookiestring.toString().replace(/^[^=]+/,"").replace("=","") : "");
  }

var myCookie = getCook('cookieName');

Saturday, 9 March 2013

how to add subTotal, grandTotal in sql query

DECLARE @t TABLE (RowNum INT IDENTITY(1,1),Grp CHAR(1), Val INT)

 INSERT INTO @t
 SELECT NULL, 1 UNION ALL
 SELECT 'A', 2 UNION ALL
 SELECT 'A', 3 UNION ALL
 SELECT 'A', 3 UNION ALL
 SELECT 'B', 4 UNION ALL
 SELECT 'A', 3 UNION ALL
 SELECT 'B', 5

 SELECT d.Grp,d.GroupTotal
   FROM (
         SELECT RowNum,
                Grp = CASE
                        WHEN GROUPING(Grp) = 0 AND GROUPING(Val) = 0 THEN Grp
                        WHEN GROUPING(Grp) = 0 AND GROUPING(Val) = 1 THEN 'Sub Total ' + ISNULL(grp,'NULL')
                        ELSE 'Grand Total'
                      END,
                GroupTotal = SUM(Val)
           FROM @t
          GROUP BY Grp,Val,RowNum WITH ROLLUP
        ) d
  WHERE RowNum > 0 OR Grp LIKE '%Total%'


Grp                  GroupTotal
NULL                   1            
Sub Total N         1            
A                          2            
A                          3            
A                          3            
A                          3            
Sub Total A         11          
B                          4            
B                          5            
Sub Total B         9            
Grand Total        21           

Friday, 1 March 2013

Write the code for selecting the 1st div, 3rd div, 3rd Last div, last div, and for even and odd div elemets ?

<div class="questions">
    <div class="myDiv"> Question</div>
    <div class="
myDiv"> Question</div>
    <div class="
myDiv"> Question</div>
    <div class="
myDiv"> Question</div>
    <div class="
myDiv"> Question</div>
    <div class="
myDiv"> Question</div>
</div>


first div : $("div.questions > div:first").css("color", "red");
3rd div : $("div.questions > div:nth-child(3)").css("color", "red");

3rd last div : $("div.questions > div::nth-last-child(3)").css 
                    ("color", "red"); 
last div : $("div.questions > div:last").css("color", "red");
even div : $("div.questions > div:even").css("color", "red");
odd div  : $("div.questions > div:odd").css("color", "red");