Pages

Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Thursday 18 June 2015

Javascript code to add GRIDVIEW row

Introduction:  JavaScript Code to add row to a GridView.

Code:

<script type="text/javascript" lang="ja">
 function AddNewRecord() {
      var grd = document.getElementById('<%=gvportfolio.ClientID%>');
      var tbod = grd.rows[0].parentNode;
      var newRow = grd.rows[grd.rows.length - 1].cloneNode(true);
      tbod.appendChild(newRow);
      }

</script>

Saturday 2 May 2015

Javascript Function to Convert Number to Words

function totext(value) {
             var fraction = Math.round(frac(value) * 100);
             var f_text = "";

             if (fraction > 0) {
                 f_text = "AND " + convert_number(fraction) + " PAISE";
             }

             return convert_number(value) + " RUPEE " + f_text + " ONLY";
         }

         function frac(f) {
             return f % 1;
         }

         function convert2number(number) {
             if ((number < 0) || (number > 999999999)) {
                 return "NUMBER OUT OF RANGE!";
             }
             var Gn = Math.floor(number / 10000000);  /* Crore */
             number -= Gn * 10000000;
             var kn = Math.floor(number / 100000);     /* lakhs */
             number -= kn * 100000;
             var Hn = Math.floor(number / 1000);      /* thousand */
             number -= Hn * 1000;
             var Dn = Math.floor(number / 100);       /* Tens (deca) */
             number = number % 100;               /* Ones */
             var tn = Math.floor(number / 10);
             var one = Math.floor(number % 10);
             var res = "";

             if (Gn > 0) {
                 res += (convert2number(Gn) + " CRORE");
             }
             if (kn > 0) {
                 res += (((res == "") ? "" : " ") +
                 convert2number(kn) + " LAKH");
             }
             if (Hn > 0) {
                 res += (((res == "") ? "" : " ") +
                     convert2number(Hn) + " THOUSAND");
             }

             if (Dn) {
                 res += (((res == "") ? "" : " ") +
                     convert2number(Dn) + " HUNDRED");
             }


             var ones = Array("", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN");
             var tens = Array("", "", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY");

             if (tn > 0 || one > 0) {
                 if (!(res == "")) {
                     res += " AND ";
                 }
                 if (tn < 2) {
                     res += ones[tn * 10 + one];
                 }
                 else {

                     res += tens[tn];
                     if (one > 0) {
                         res += ("-" + ones[one]);
                     }
                 }
             }

             if (res == "") {
                 res = "zero";
             }
             return res;
         }

Saturday 1 June 2013

Refreshing Parent page from child page using JavaScript

use this javascript function on ypur child page :
 <script type="text/javascript">
    function closechildwindow() {
        window.opener.document.location.href = '(parent page url)';
        window.close();
    }
</script>

now in the body tag of your child page call the function like this:
<body onunload="closechildwindow()">

Sunday 12 May 2013

Slide out Tab using javascript

Code For <head></head> Secction :-

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
<script src="http://tab-slide-out.googlecode.com/files/jquery.tabSlideOut.v1.3.js" type="text/javascript"></script>

<script type="text/javascript">
    $(function () {
        $('.slide-out-div').tabSlideOut({
            tabHandle: '.handle',                     //class of the element that will become your tab
            pathToTabImage: 'http://wpaoli.building58.com/wp-content/uploads/2009/09/contact_tab.gif', //path to the image for the tab //Optionally can be set using css
            imageHeight: '122px',                     //height of tab image           //Optionally can be set using css
            imageWidth: '40px',                       //width of tab image            //Optionally can be set using css
            tabLocation: 'right',                      //side of screen where tab lives, top, right, bottom, or left
            speed: 400,                               //speed of animation
            action: 'click',                          //options: 'click' or 'hover', action to trigger animation
            topPos: '200px',                          //position from the top/ use if tabLocation is left or right
            leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
            fixedPosition: true,                      //options: true makes it stick(fixed position) on scroll
            onSlideOut: function () {
                alert('Opened');
            },
            onSlideIn: function () {
                alert('Closed');
            }
        });

    });
</script>

<style type="text/css">
.slide-out-div {
  padding: 20px;
  width: 250px;
  background: #ccc;
  border: 1px solid #29216d;
 }    
 </style>


Code for <body></body> Section: -

<div class="slide-out-div">
    <a class="handle" href="http://link-for-non-js-users.html">Content</a>
     <h1> Feedback form</h1>
    <table class="container">
     
        <tr>
            <td class="style1">
                <asp:Label ID="Label6" runat="server" Text="Mail ID"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style1">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style1">
                <asp:Label ID="Label7" runat="server" Text="Feedback"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="TextBox7" runat="server" TextMode="MultiLine" Height="50px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style1">
                &nbsp;</td>
            <td>
                <asp:Button ID="Button1" runat="server" Text="Button" />
            </td>
        </tr>
    </table>
 </div>