ASP.NET - Javascript Code Comparing Two textbox's value

Asked By myzonal.com myzonal.com
27-Oct-09 03:21 AM

i ve take two textboxes so i want to compare both textboxes value and print a message that value not same like this with javascript so plz help me soon??????

thanks and regards

vivek

reply  reply

27-Oct-09 03:31 AM
Hi,
Your best bet is a custom validator or compare validator, however here you go: if both controls are server controls: <script language="javascript"> function check() {
 var a = document.getElementById('<%=label.ClientID%>');
 var b = document.getElementById('<%=textbox.ClientID%>');  if (a.innerText == b.value) {
  return true;
 } else {
  return false;
 }
} </script>

Re  Re

27-Oct-09 03:31 AM
Below function will do it for you

function StringCompare()
{
var string1 = document.getElementById("TextBox1").value;
var string2 = document.getElementById("TextBox2").value;

if(string1 == string2)
{
alert("Both values are same.");
}
else
       {
alert("Values are different.");
}
return false;
}
//in the button event call the javascript
<asp:Button id="Button1" OnClientClick="StringCompare();" runat="server" Text="Button1"/>

Javascript Code Comparing Two textbox's value  Javascript Code Comparing Two textbox's value

27-Oct-09 03:31 AM
<html>
<head>
<title>Compare</title>
<script type="text/javascript">
<!--
function compare1()
{
var str1 = document.getElementById("string1").value;
var str2 = document.getElementById("string2").value;
if(str1 != str2)
{
if(str1 > str2)
{
document.getElementById("ans").value= str1 + " Greater than " + str2;
}
else
{
document.getElementById("ans").value= str1 + " Less than " + str2;
}
}
else
{
document.getElementById("ans").value= str1 + " Equals " + str2;
}
}
// -->
</script>
</head>
<body>
 
<h1> Compare</h1>
<hr />
 
<p>Press F5 or Refresh to load script again. This is a program to Compare two input strings.</p>
<form name = "compare" action = "">
<table border = "1">
<caption>Compare</caption>
<tr><td>Enter any String</td>
<td><input name = "string1" type = "text" />
</td></tr>
<tr><td>Enter Second String</td>
<td><input name = "string2" type = "text" />
</td></tr>
<tr><td>Output Comparison</td>
<td><textarea name="ans">
</textarea>
</td></tr>
<tr><td><input type = "button" value = "Compare"
onclick = "compare1()" /></td></tr>
</table>
</form>
</body>
</html>
Compare Textbox' Values using JS  Compare Textbox' Values using JS
27-Oct-09 04:34 AM

Take 2 textboxes and compare their's values like

function txtValuesCompare()

{

     var txt1 = document.getelementbyid("textbox1").value;

     var txt2 = document.getelementbyid("textbox2").value;

     if(txt1 == txt2)

    {

          alert("values are same");     

          return true;  

    }

    else

    {

          alert("values are not matching"); 

          return false;      

    }

}

<asp:textbox id="textbox1" runat="server"></asp:textbox>

<asp:textbox id="textbox2" runat="server"></asp:textbox>

<asp:button id = "btnCompare" runat = "server" onclientclick = "txtValuesCompare();" text="Compare" /><asp:button>

Create New Account
help
you get records number from 5 to 15 in a dataset of 100 records? Write code. Answer1 DataSet ds1 = new DataSet(); String strCon = ”data source = IBM-6BC8A0DACEF;initial catalog = pubs;integrated 8000 Answer3 The business logic is the aspx.cs or the aspx.vb where the code is being written. The presentation logic is done with .aspx extention. How do you define in Sql server as var_name int How do you separate business logic while creating an ASP.NET application? There are two level of asp.net debugging 1. Page level debugging For this we have to edit the page level debugging Microsoft-provided calendar control, how do you develop it? Do you copy and paste the code into each and every page of your application? Create the Calendar User Control The control The control itself will take care of the date display How can you deploy an asp.net application ? You can deploy an ASP.NET Web application using any one of the
Net hi friends Any one send frequently asked Important questions in C# .Net, ADO .Net, Asp .Net and Sql Server. . . . . . . . tx in Advance. . . . . . Hi, Find this. . (B)What is an IL? (B is CTS? (B)What is a CLS (Common Language Specification)? (B)What is a Managed Code? (B)What is a Assembly? (A) What are the different types of Assembly? (B) What C#? (I) what is the difference between System exceptions and Application exceptions? (I)What is CODE Access security? (I)What is a satellite assembly? (A) How to prevent my .NET DLL in .NET? (B) When we use windows API in .NET is it managed or unmanaged code? (I)What is COM? (A) What is Reference counting in COM? (A) Can you describe What are dependencies in cache and types of dependencies? (A)Can you show a simple code showing file dependency in cache? (A) What is Cache Callback in Cache? (A) What is scavenging? (B) What are different types of caching using cache object of ASP.NET? (B) How can you cache different version of same page using ASP.NET cache object
Migration from ASP to ASP.net How to convert ASP site to ASP.NET site using C# http: / / www.asp.net / downloads / archived-v11 / migration-assistants / asp-to-aspnet hi, ASP.NET framework is very much different from unstrucured ASP and there is no correct way to
Tracing in ASP.NET? hi all, what is tracing? how to achieve tracing in asp.net? different ways of doing tracing? thanks and regards Aman Khan hi. . Tracing in ASP.NET 2.0 Tracing is a way to monitor the execution of your ASP.NET application. You can record exception details and program flow in a way that doesn't
session useful in web how to session useful in web plz send me details with code in vb best benifit of the session is user based mean u can differentiate login user in different way • Process independent. ASP.NET session state is able to run in a separate process from the ASP.NET host process. If session state is in a separate process, the ASP.NET process can come and go while the session state process remains available. Of course, you ASP, too. • Support for server farm configurations. By moving to an out-of-process model, ASP.NET also solves the server farm problem. The new out-of-process model allows all