Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

how to email validation in javascript



<asp:TextBox ID="txtEmailID" ClientIDMode="Static" runat="server" CssClass="Email"                      ></asp:TextBox>


$(".Email").bind('change', function (event) {
        var testEmail = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i;

        if (testEmail.test($(this).val()))
            $(this).css('border', '1px solid silver');
        else {
            alert('Please Enter valid email');
            $(this).css('border', '1px solid red');
            $(this).val("");
            $(this).focus();
            return false;
        }
    });

how to get session value in javascript



var UserID = '<%= Session["UserID"]%>';

how to print specific div in javascript

Description
Here i will explain how to print specific element using javascript in our website.
It is simple and small code to print your element from web application.

Just you need to pass element id parameter like the following javascript function:

<script type="text/javascript">
        function printDiv(divID) {
            //Get the HTML of div
            var divElements = document.getElementById(divID).innerHTML;

            //Get the HTML of whole page
            var oldPage = document.body.innerHTML;

            //Reset the page's HTML with div's HTML only
            document.body.innerHTML = divElements;

            //Print Page
            window.print();

            //Restore orignal HTML
            document.body.innerHTML = oldPage;
        }

    </script>