...

View Full Version : Help needed - New to Javascript!!!



dambuster
12-30-2010, 06:34 PM
I'm working very hard to create a dynamic web-site for use in the education sector using server-side php/MySQL and client-side HTML with javascript.
I have a logon page (index.php) which looks to see if the cookie 'mylogon' is set with the value 'Again'. This cookie is set when the PHP element on the server detects an invalid username/password combination. If so I have a javascript function (see below) call from the HTML <body onload="check_invalid_user()">

I know that the function Get_Cookie is working ok and that the javascript variable 'again' has the value 'Again' in it and has a length of 5. The alert function is not executed though.

function check_invalid_user()
{
again = Get_Cookie('mylogon');
// document.write(again);
// document.write(again.length);
If (again == 'Again')
{
alert("User-id and/or password incorrect -- Please re-enter");
}
}

=============

Any help would be appreciated:confused: Many thanks in advance. (Yeah you guessed it I'm new and raw to this stuff.

Old Pedant
12-30-2010, 06:55 PM
Ummm...and what do you do if the user has cookies turned off????

You may want to turn your logic around: Unless the cookie value is valid, make them login again.

But it's not hard to "spoof" cookies, so maybe you shouldn't be using cookies, at all??

Not clear to me why you want to do any of this in JavaScript, instead of doing it all in the PHP coding.

dambuster
12-30-2010, 06:59 PM
Ok 'old pedant' so I guess there's another way - would you care to hint. I'd still like to know why the
If (again == 'Again')
{
alert("User-id and/or password incorrect -- Please re-enter");
}

doesn't execute.

Thanks dambuster

Old Pedant
12-30-2010, 07:06 PM
The keyword is if, not If -- JavaScript is case sensitive.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum