Compare 2 fields before submitting

How can I compare two fields to be sure they are the same onclick?  These are password fields and I did not want to have to submit the form to compare them if I can do it this way instead.

=)
JuniorBeeAsked:
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.

BogoJokerCommented:
Hi JuniorBee,

You can create a javascript function.  It would really help if you gave more information but I can construct a situation for you.
Another note is that if the information is sensitive you may want to check serverside, since javascript may be turned off by the user that is visiting your site, while a server-side lanugage like PHP or ASP will be 100% guarnteed to run.

Joe P
0
JuniorBeeAuthor Commented:
ahhh I see. Good point.  I think I will just check it using ASP since I just made a function to check that the username is not already used.  Good to know.  I have other stuff I should probably convert to ASP as well.

For my info, how do I completely disable the javascript in my browser (IE6) so that I can test any security holes in my code.  That would be helpful too!  Then I can see what needs to be in ASP and what's OK to leave in Javascript.
0
danrosenthalCommented:
The best approach would be to use both forms of validation: Server-side and Client-side. Client-side validation usually makes the site easier for your users.

I would recommend using Server-side validation 100% of the time (since it cannot be turned off like Client-side validation can) and adding Client-side validation (javascript) where you both think it is appropriate and have the time desire and code it.

-Dan
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.

danrosenthalCommented:
Here is an example of password validation:

<SCRIPT>
function checkform(){
      if(document.myform.pw1.value.length==0){
            alert('password cannot be blank');
            return false;
      }else if(document.myform.pw1.value!=document.myform.pw2.value){
            alert('password must match');
            return false;
      }
      return true;
}
</SCRIPT>

<FORM name="myform" onsubmit="return checkform();">
      <INPUT type="password" name="pw1"><br>
      <INPUT type="password" name="pw2"><br>
      <INPUT type="Submit">
</FORM>
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
JuniorBeeAuthor Commented:
Anybody got any client side pw validation script?  One for onclick?
0
JuniorBeeAuthor Commented:
Ack, you musta hit sumbit just before me eh?
0
BogoJokerCommented:
Also to disable javascript in IE:
With IE5/5.5, to disable JavaScript you have to change the security settings. You'll find the setting under Tools->Internet Options->Security Tab bar->Custom Level->Disable Active scripting (at the end of the list)

I got that and tryed it.  Got it from:
http://www.jguru.com/faq/view.jsp?EID=131290

Joe P
0
danrosenthalCommented:
yep :)
So, is that the kind of code you were looking for?
0
BogoJokerCommented:
Looks good dan.  Also it is intuitive, by checking two conditions, if the first is blank, (no need to check the second given that your second check is), if the two are equal or unequal.

Joe P
0
JuniorBeeAuthor Commented:
Thanks a bunch!  I awarded the points according to the question I asked although it was all so very helpful!!!
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
JavaScript

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.