Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

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.

=)
0
JuniorBee
Asked:
JuniorBee
  • 4
  • 3
  • 3
3 Solutions
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now