• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

need some quick JavaScript help

Status
Not open for further replies.

Ecrofirt

Member
ok, I'm trying to make a basic password page for a friend that he's going to use for some project he's doing.

There's two textboxes, and the user enters his username & password. WHen you click on the button, it's supposed to send the value of those textboxes to the function. I can't figure out how to do that, though.

Here's my code:

Code:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function myfunction(user,pass){
alert("in function");
if (user=="test" && pass=="test") { 
window.location="www.nformant.net";
alert("works!");
}else { alert("doesn't work")};
}
</SCRIPT>
</head>

<body>
<form name="myform">
<LABEL ACCESSKEY=U>User name: <INPUT TYPE=text NAME=user SIZE=12 MAXLENGTH=8></LABEL><br>
<LABEL ACCESSKEY=P>Password: <INPUT TYPE=password NAME=pass VALUE="test" SIZE=12 MAXLENGTH=12></LABEL><br>
<input type="button" value="enter password" onClick="myfunction(user,pass);">
</form>
</body>



</html>
 

Ecrofirt

Member
nope.

The code works if I change the button like to this:

Code:
<input type="button" value="enter password" onClick="myfunction('test','test);">
 

explodet

Member
Code:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function myfunction(theform){

user = theform.user.value;
pass = theform.pass.value;

alert("in function");
if ((user=="test") && (pass=="test")) { 
window.location="http://www.nformant.net";
alert("works!");
}else { alert("doesn't work")};
}
</SCRIPT>
</head>

<body>
<form name="myform">
<LABEL ACCESSKEY=U>User name: <INPUT TYPE=text NAME=user SIZE=12 MAXLENGTH=8></LABEL><br>
<LABEL ACCESSKEY=P>Password: <INPUT TYPE=password NAME=pass VALUE="test" SIZE=12 MAXLENGTH=12></LABEL><br>
<input type="button" value="enter password" onClick="myfunction(this.form);">
</form>
</body>
</html>

I fixed quite a few things in this form.
 
Status
Not open for further replies.
Top Bottom