Search This Blog

Thursday, February 2, 2012

JAVA SCRIPT VALIDATION

JAVASCRIPT.JS FILE


function dateobject() {
    var d = new Date();
    document.write("Full Date : "+d);
    document.write("<br>");
    document.write("<br>");
    document.write("Date is " + d.getDate());
    document.write("<br>");
    document.write("<br>");
    document.write("<br>");
    document.write("Day " + d.getDay());
    document.write("<br>");
    document.write("<br>");
    document.write("Current Time   (HH:MM:SS) are " + d.getHours()+" : "+d.getMinutes() +" : "+d.getSeconds() );
    document.write("<br>");   
    document.write("<br>");
    document.write("Current Time (Minutes) are " + d.getMinutes());
    document.write("<br>");
  
}

on ASPX PAGE

 <script src="datefunction.js" type="text/javascript"></script>



<input type="button" name="Button1" value="Date" onclick="dateobject()"/>



CHANGE IMAGE USING JAVASCRIPT

<h1>
                Change Image using Javascript</h1>
            <img src="images/one.jpg" id="img1" alt="This is image " onmouseover="f1()" onmouseout="f2()" height="200px"
                width="200px" />


 <script type="text/javascript">
        function f1() {
            img1.src = "images/two.jpg";

        }
        function f2() {
            img1.src = "images/three.jpg";
            popupwindow = window.open('Date1.aspx', 'Date', 'height="1024px,width="768px""');
        }
   
    </script>


USING JAVASCRIPT TEXTBOX

 <script type="text/javascript" language="javascript">
        function changecolor() {
            if (document.getElementById("txtusername").value != "") {
                document.getElementById("txtusername").style.backgroundColor = "#00CC00";
                document.getElementById('lblusername').style.color = '#00CC00';
                document.getElementById('lblusername').innerHTML = "Username is Entered";
            }//end of if

            else {
                document.getElementById("txtusername").style.backgroundColor = "#FF0000";

            }//end of else
        }//End of function
    </script>

<asp:TextBox ID="txtusername" runat="server" onmouseover="changecolor();" onmouseout="changecolor();">
                    </asp:TextBox>


VALIDATION USING JAVASCRIPT

<script type="text/javascript">
        function validate() {
          
            //if (user.value == "hitesh" && pass.value == "hitesh") {
           if (document.getElementById("txtname").value == "hitesh" && document.getElementById("txtpass").value == "hitesh") {
                alert("Congragulations !!!");
            }
            else {
                document.getElementById("Label1").innerHTML = "Enter Valid Username";
                document.getElementById("Label2").innerHTML = "Enter Valid Password";
               
                alert("Username / Password is not valid");
            }
        }

    </script>
<asp:Button ID="btnsubmit" runat="server" Font-Bold="True" ForeColor="#FF3300" Height="31px"
                        Text="Submit" Width="80px" OnClientClick="validate();" />


OPEN ANOTHER PAGE USING JAVASCRIPT

    <script language="javascript" type="text/javascript">
        function link1() {
            window.location = "http://localhost:49374/Javascript_123/login.aspx";
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Go to Login Page of This website:<asp:Button ID="btnlogin" runat="server" Text="Login" OnClientClick="link1()" />