javascript cancel

I got two variables  and I want to compare the values of those two variables and if variable 2 is not equal to variable 1 then i want a message box saying you cannot continue.

dim variable1 as double
dim variable2 as double.

The value of these two variable changes whenever a user puts values on the form. But when the user presses a button it has to compare the values and if they are not same then a message box should pop up.

if variable2 = variable1

msgbox
else
do rest
end if

i am using asp.net with vb.net code.

please help.

Pratik
pratikshahseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kiran Paul VJComputer EngineerCommented:
<html xmlns="http://www.w3.org/1999/xhtml">
<script language="javascript">
function compare1()
{
      if(document.form1.pass1.value!=document.form1.pass2.value)
      {
            alert('Passwords does not match');
            return false;
      }
return true;
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" onsubmit="return compare1()">
<p>
  <input name="pass1" type="text" id="pass1" />
</p>
<p>
  <input name="pass2" type="text" id="pass2" />
</p>
<p>
  <input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>
0
nayernaguibCommented:
You can use this trick:

        If firstValue = secondValue Then
            Dim script As String = "<script>alert(""Values are equal"")</script>"
            Response.Write(script)
        Else
            'do other things
        End If

_______________

  Nayer Naguib
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kiran Paul VJComputer EngineerCommented:

oops little problem , put the script inside the head tag.
u can also check if the fields are empty by

function compare1()
{
 if(document.form1.pass1.value=='')
 {
  alert("Please enter a value in the fieldname");
  return false;
  }
if(document.form1.pass2.value=='')
 {
   alert("Please enter a value in the fieldname");
   return false;
  }    
if(document.form1.pass1.value!=document.form1.pass2.value)
     {
          alert('Passwords does not match');
          return false;
     }
return true;
}
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Kiran Paul VJComputer EngineerCommented:

the main part is that in the form onsubmit event u should call the function like this
onsubmit="return compare1()"
otherwise it wont work correctly
0
nayernaguibCommented:
MsgBox does not work in ASP .NET simply because ASP .NET code executes on the server, not inside your browser. Your browser only renders the HTML result of the code execution. By using the piece of code that I posted above, you write a single line of JavaScript in the HTML document to be displayed by the browser, which causes the browser to execute the script, displaying the required message.

_______________

  Nayer Naguib
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.