Feb 15, 2014

how to call javascript function on button click in asp.net

Create a function like
<script type="text/javascript" language="javascript">
 function ValidateForm()
    {
           var Form=document.getElementById('frmDemo');
           alert(Form.txtbox1.value);
           alert(Form.txtbox2.value);
           if(parseFloat(Form.txtbox1.value)<parseFloat(Form.txtbox2.value))
            {
                alert('hello all');
                document.getElementById('txtbox1').focus();
                return false;
            }
//or
            if(parseFloat(Form.txtbox1.value)==parseFloat(Form.txtbox2.value))
            {
                alert('hello all');
                document.getElementById('txtbox1').focus();
                return false;
            }
//or
            if(parseFloat(Form.txtbox1.value)<parseFloat(Form.txtbox2.value))
            {
                alert('hello all');
                document.getElementById('txtbox1').focus();
                return false;
            }
    }
 
</script>
now we can call like 
<asp:Button ID="BtnSubmit" Text="Proceed" runat="server" OnClientClick="return ValidateForm();"/>


No comments:

Post a Comment