Click to See Complete Forum and Search --> : Inconsistent function behavior


llanitedave
04-18-2004, 11:17 PM
I wrote a function to make use of the hex_md5 downloaded from
http://pajhome.org.uk/crypt/md5 .
Its purpose is to implement a challenge-response password system off a PHP server. I had it modify the password field before submittal, like so:

in the password field:
onblur = "return pass_hash(this)"

Here is the pass_hash function:

function pass_hash(logForm) {

var passhash = hex_md5(password.value); // hash the password as entered
passhash = hidden_hash.value + passhash; // merge it with the hidden field
password.value = hex_md5(passhash); // hash the resulting string
}

As above, using the onblur event, it works just fine.

THEN, I called the pass_hash function from inside another function,
named "valid_form(logForm)"

The function checks to make sure the user and password fields are not blank, and sends an alert if they are. That works ok too.

HOWEVER, when I call
password.value = pass_hash(logForm);

From inside valid_form, it returns "undefined" for the password value.

Is this a scope problem? The hex_md5 function is defined in an external .js file that both of the other functions have access to...

I'm really stumped.

llanitedave
04-19-2004, 12:55 PM
OK -- found the problem! I was changing "password.value" inside the function, but not passing a return value. By referencing it as "password.value = pass_hash(logForm);"
It was looking for a nonexistant return value.

I just called the function straight, without an assignment, and it works.