Thursday 22 September 2011

How To Validict Textbox Through Javascript

Firstly make the function in Javascript to validate Textbox:-

/*We can write this code under <script src="JScript.js" type="text/javascript">
function check_blank(fldid, msgid) {
    var fld = document.getElementById(fldid);
    if (fld.value.length == 0 || fld.value.charAt(0) == " ") {
        document.getElementById(msgid).innerHTML = "Require field has not been filled";
        return false;
    }
    document.getElementById(msgid).innerHTML = "&nbsp";
    return true;
}
 </script>

Call this function on Aspx page:-
Like if u want to validate Textbox  then simple call upper code on aspx page like as:-

  <asp:TextBox ID="Tname" onblur="return check_blank(this.getAttribute('id'),'fname')" runat="server" Height="32px" Width="285px"></asp:TextBox>
<td><span id="fname" style=" font-size:x-small;color:red;"></span></td>

No comments:

Post a Comment