PDA

View Full Version : Comparing Request Object items with javascript


AbsolutMauser
07-07-02, 21:01
Greetings,

I am trying to determine if two submitted passwords are equal. So, I have a litte "if" line like so:

if(Request.Form("password") != Request.Form("verifypassword"){
return false;
}

However, no matter what is in the password and verifypassword fields, it always returns false, even if they are the same! (verified by using an =Request.Form("password") and =Request.Form("verifypassword") in the HTML doc to check the values outside of the password field. I have also tried creating string objects called pass1 and pass2, saving the two Request.Form items to them, and then comparing them as pass1.toString() and pass2.toString() again to no avail. Anyone have any thoughts as to what is going on in my app? Thanks!

~AbM

buro9
07-08-02, 09:12
you're 'not equals' is wrong if you're in asp... try <>

e.g.

if (Request.Form("password") <> Request.Form("verifypassword") {
return false;
}


if you're in javascript, then this should be part of the onsubmit() for the form, and could be written like:

var form = document.forms["yourFormName"];
if (form.password1.value != form.password2.value) {
return false;
}

cheers

david k

AbsolutMauser
07-08-02, 12:30
I get errors when I use <>. I am using javascript in ASP, not VBScript. I have now tried a construction where I use == to determine if the two are equal instead of determining if they are unequal, however, this also fails every time. I can't figure this out! :mad:

~AbM

buro9
07-08-02, 13:05
can you mail me the whole of that HTML page, i'll go through it and mail back the solution.

cheers

david k

AbsolutMauser
07-08-02, 13:25
I sent you a private message with a link to the code. Thx

~AbM

buro9
07-08-02, 16:51
Attached file shows basic javascript validation, I tested it and it works fine.

As I said in the PM, I was surprised to see you code ASP pages using JScript and thought that you were actually trying to do it client side. You may need to check what JScript documentation there is for a server side solution... alternately switch to VB or C# and I'll be able to help ;)

Anyhow, attached file should solve part of it for you.

AbsolutMauser
07-08-02, 20:02
Thanks! I also found that using the String() function around Request objects works as well and solved another problem I was having. Apparently, Request objects do not actually return strings, they return some other nebulous form of data just like in (duh) other object oriented applications. When comparing two objects, even if they carry the same value, the will not necessarily evaluate as equals. I was attempting to define new string objects using "new String()" and then the .toString() method to compare them (this failed). I was not aware that simply enclosing an object in String() would cause it to be evaluated as a string. Nonetheless, all is happy again. Thanks for your help!

~AbM

buro9
07-09-02, 03:04
Ah yes! Of course, in C# I've just spent the last few days mostly typing .ToString() at the end of everything... sure I was building an app, but god you get bored of typing that!