Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript
Hi,
I used Two textboxes in my asp.net application. i want to compare that two values on buuton click. How to Check that two textbox values and display alert message using javascript and how to call that function on button click event.
 

If any one know about this Help me.
 
Regards
Nanda Kishore.CH
Posted 7-Jul-12 1:29am
Comments
Member 11268391 at 29-Nov-14 8:22am
   
How to call javascript function on text
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try this...its so simple
 
<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>
 
Call ValidateForm() on Button OnClientClick
<asp:Button ID="BtnSubmit" Text="Proceed" runat="server" OnClientClick="return ValidateForm();"/>
 

Thanks
Ashish
 
Mark it solution if this is your answer
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

In asp button there is a property called OnClientClick there u can specify the java script function like given below
 
<asp:button id="btnSave" tabIndex="32" runat="server" CssClass="btn" OnClientClick = "return compare()"Text="Save"></asp:button>
 
in ur javascipt function now u can write the compare function like given below
 
<script language="javascript" type="text/javascript">
 

            function compare() {
 
var txt1 = document.getElementById('txt1').value; // textbox 1 ID is txt1
var txt2 = document.getElementById('txt2').value; // textbox 2 ID is txt2

                if (txt1 == txt2) {
                    alert("both are same");
                }
                else {
                    alert("both are different");
                }
 
            }
 
        </script>
 

Check this out.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

USe This:
 
<asp:button id="Btn_submit" onclientclick="return validate()" onclick="Btn_submit_Click()"/>
 
 
Here The OnClientClick is used for calling the javascript function. Here validate is a javascript function.
 
<script type="text/javascript">
function vaildate()
{
...................
...................
....................
}
</script>
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

You can use this in page_load
 
Button1.Attributes.Add("onclick", "return javascriptfunction();");
 
if you don't want postback always return false;
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 285
1 DamithSL 265
2 CPallini 195
3 Maciej Los 175
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100