Calling a function...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DSL

    Calling a function...

    I'm pulling my little hair that's left out trying to figure out how I can
    call a function from within a function. Here's the deal... and yes I know I
    should be using PHP!

    I have a password login screen for three users who have individual
    pre-assigned passwords so i need some logic testing as per below


    // ========START OF CODE=========

    //This is the function to find out who is logging in
    function validate()
    {
    //Change case from the input
    var usrid=document. form.usrid.valu e.toLowerCase()

    //Simple if statement for the who's logging in logic
    if(usrid=="TEST ") //**??THIS IS WHERE I HAVE PROBLEM 1 (FOR
    SURE)??**
    else
    if(usrid=="") alert("ID REQUIRED!")
    }

    //This is the password check for the user TEST
    function validateTESTIDP wd()
    {
    //Change case from the input
    var pwd=document.fo rm.pwd.value.to LowerCase()

    //Validate password
    if(pwd=="TEST") //**?? THIS IS WHERE I HAVE PROBLEM 2 (MAYBE)??**
    else
    alert("Password Incorrect!")
    }

    // ========END OF CODE=========

    OK, so problem 1: How can I call the validateTESTIDP wd() function
    and problem 2: After confirming the identity of user TEST I want to open up
    a page in the current frame. Does anyone know how to manipulate my frames
    from this point?

    All help appreciated.

    Cheers,

    Matt


  • Mick White

    #2
    Re: Calling a function...

    DSL wrote:


    function popup(txt){aler t(txt)}
    function validateTESTIDP wd(){
    if(document.for m.pwd.value.toL owerCase()=="te st"){
    popup("Password Correct");
    return;
    }
    alert("Password Incorrect!")
    }

    Mick

    Comment

    • Robert

      #3
      Re: Calling a function...

      In article <c63m3u$79g$1@s parta.btinterne t.com>,
      "DSL" <matt.sapsford@ btinternet.com> wrote:
      [color=blue]
      > I'm pulling my little hair that's left out trying to figure out how I can
      > call a function from within a function. Here's the deal... and yes I know I
      > should be using PHP![/color]

      What is the point of check the userid & password in javascript? The
      user can just read the javascript code.
      [color=blue]
      > I have a password login screen for three users who have individual
      > pre-assigned passwords so i need some logic testing as per below[/color]
      [color=blue]
      >
      > OK, so problem 1: How can I call the validateTESTIDP wd() function
      > and problem 2:[/color]

      Below is an example of checking the userid. The code of the HTML form
      could be improved, but it demonstrates what you need.

      Robert

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <html>
      <head>
      <title>Chapte r 4 - Scripting Exercise 5</title>

      <SCRIPT type="text/javascript">

      //This is the function to find out who is logging in
      function validate(userid )
      {
      alert("Checking for " + userid);
      // Change case from the input
      // -- so you need to check in lower case
      var userid=userid.t oLowerCase()

      //Simple if statement for the who's logging in logic
      if(userid=="tes t")
      {
      // Suggest you put the trailing if code in a block.
      // It's ease to forget when adding a line.
      alert(userid + " is a valid userid");
      return true
      }
      else
      if(userid=="")
      {
      // Tell the user how to fix the problem not what is wrong.
      alert("Please enter a valid userid");
      return false
      }
      else
      {
      alert("Please enter a valid userid. This one is not known.");
      return false
      }


      }
      </script>

      </head>
      <body>
      <form action="" method="post" name="submituse rid"
      onSubmit="answe r = validate(docume nt.forms[0].theUserid.valu e);
      alert('valid user = ' + answer);">
      <b>What is your userid?&nbsp&nb sp
      <input type="text" id="theUserid" size="10" maxlength="16"> <br>
      <input type="submit" name="submit" value="Check userid"><br>
      <input type="reset" name="reset" value="Reset Form">
      </form>
      </body>
      </html>

      Comment

      Working...