Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Location
    Birmingham (UK)
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Help needed - New to Javascript!!!

    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 Many thanks in advance. (Yeah you guessed it I'm new and raw to this stuff.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,211
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Location
    Birmingham (UK)
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,211
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    The keyword is if, not If -- JavaScript is case sensitive.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    dambuster (12-30-2010)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •