469,625 Members | 1,109 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

Calling a function...

DSL
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.value.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 validateTESTIDPwd()
{
//Change case from the input
var pwd=document.form.pwd.value.toLowerCase()

//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 validateTESTIDPwd() 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
Jul 23 '05 #1
2 1140
DSL wrote:
function popup(txt){alert(txt)}
function validateTESTIDPwd(){
if(document.form.pwd.value.toLowerCase()=="test"){
popup("Password Correct");
return;
}
alert("Password Incorrect!")
}

Mick
Jul 23 '05 #2
In article <c6**********@sparta.btinternet.com>,
"DSL" <ma***********@btinternet.com> wrote:
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!
What is the point of check the userid & password in javascript? The
user can just read the javascript code.
I have a password login screen for three users who have individual
pre-assigned passwords so i need some logic testing as per below
OK, so problem 1: How can I call the validateTESTIDPwd() function
and problem 2:


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>Chapter 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.toLowerCase()

//Simple if statement for the who's logging in logic
if(userid=="test")
{
// 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="submituserid"
onSubmit="answer = validate(document.forms[0].theUserid.value);
alert('valid user = ' + answer);">
<b>What is your userid?&nbsp&nbsp
<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>
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Muthu | last post: by
6 posts views Thread by jchao123 | last post: by
1 post views Thread by Jesse McGrew | last post: by
5 posts views Thread by Nick Flandry | last post: by
2 posts views Thread by Geler | last post: by
15 posts views Thread by dspfun | last post: by
11 posts views Thread by briankirkpatrick | last post: by
16 posts views Thread by teju | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.