Closed Thread Icon

Topic awaiting preservation: Password exersice. (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8704" title="Pages that link to Topic awaiting preservation: Password exersice. (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Password exersice. <span class="small">(Page 1 of 1)</span>\

 
Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 06-09-2003 00:51

Hi, guys. How was your weekend?
It was great, was it?
I had pretty good time with my mates. It was one of the busiest weekend for a couple of months.
Anyway, would you have time to read my thread?
What I am coding is passowrd form.

my mission:
[quote]User enter two password fields. If they are identical, print "thanks for log in" on the screen. Otherwise "no, no, no". [/qutoe]

My code is here:

code:
<html>
<head>
<script type="text/javascript">
function logIn(){

var one=document.theForm.pwo.value;
var two=document.theForm.pwt.value;

if(one=two){
document.write("Thanks for log in!");
}else{
document.write("No, No, No!!");
}
}
</script>
</head>

<body>

<form name="theForm">
<p>
Enter your password:
<input type="password" name="pWo">
<p />
<p>
Enter your password again:
<input type="password" name="pWt">
<p/>
<p>
<input type="button" value="Submit" onClick="logIn()">
<input type="reset" value="Reset">
</p>
</form>

</body>

</html>



I thought it was quite easy. But I am afraid my code doesn't work properly. Do I declare variable colloctly? Any problems??? Error message said that document.theForm.pwo is not an object....Hhmmm.....why????


Hiroki Kozai

jstuartj
Bipolar (III) Inmate

From: Mpls, MN
Insane since: Dec 2000

posted posted 06-09-2003 02:23

Well for starters, your, variables don't match you have pWo and pNt in your form and pwo and pnt in your function. Variables are case sensitive. You are also using using the wrong equals sign == for the if statement.

I also changed your function call to pass the form object to the function by using this.form, to do the you need to alter your function and added a parameter to the function header, it's not necessary to be lable it "form" but that makes it easy to rember. You could call it larry or myFrom if you want to, it's just a variable name. I simply acts as a place holder for first parameter passed to it in this case "this.form"


code:
<html>
<head>
<script type="text/javascript">

function logIn(form){

var one=form.pWo.value;
var two=form.pWt.value;

if(one==two){
document.write("Thanks for log in!");
}else{
document.write("No, No, No!!");
}
}
</script>
</head>

<body>

<form name="theForm">
<p>
Enter your password:
<input type="password" name="pWo">
<p />
<p>
Enter your password again:
<input type="password" name="pWt">
<p/>
<p>
<input type="button" value="Submit" onClick="logIn(this.form)">
<input type="reset" value="Reset">
</p>
</form>

</body>

</html>



This should work, I would use longer variable names when mixing caps and lower case. Three letter passwords seems odd to me and makes it a little hard to read.

One tip, there are lots of sites out there with example and free code. I often use them as a referance when I don't know how something works. Find something similar and rip it apart to see how it works and to see if there are better ways to acomplish the task.

J. Stuart J.

[This message has been edited by jstuartj (edited 06-09-2003).]

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 06-09-2003 03:33

Hi,mate.
Thanks a lot for your help!
It is working perfectly.
Many thanks.
Well, could I ask something about your code?
Is there any particular reason to do like

quote:
function logIn(form){ -----------}
onClick="logIn(this.form)">



Argument stuff often make me confused.....


Hiroki Kozai

wrayal
Bipolar (III) Inmate

From: Cranleigh, Surrey, England
Insane since: May 2003

posted posted 06-09-2003 19:06

About the
function logIn(form){ -----------}
onClick="logIn(this.form)">
thing, what this means is you can use the function with different forms. "this.form" is just a reference to the form submitted. So, if you click a secind button in another form and pass "this.form" again, it will refer to the form the second button was in. Otherwise, you woul have to have a different function for each form. Hope that helps.

Wrayal

Go to kimber-ja.demon.co.uk and click on the link to the raytracer! It's mine!

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 06-10-2003 04:35

Hi, mates.
Many thanks for your helps.
I have been coding quite a lot today.
Soon I am going to be in database class.
Now I am studying SQL in that class.
My tutor doesn't prepare for the class much.
SQL stands for She is Quite Lazy. By my best friend, John.
Cya.

Hiroki Kozai

« BackwardsOnwards »

Show Forum Drop Down Menu