Forum Moderators: open

Message Too Old, No Replies

Cannot pass login info to the next .asp page(s)

         

fototex

8:18 pm on Jun 2, 2010 (gmt 0)

10+ Year Member



Hi coders,

I have a login form which has the following code:


<p>
Username:<span><input type="text" id="uid" name="uid" size="14"/> </span>
Pass:<span><input type="password" id="pwd" name="pwd" size="14"/></span>
<a onclick="return loginload()" href="#" class="btn">Enter</a>


Here is the loginload script directs me to the following page upon Enter:


function loginload() {
window.location="step1.asp";
}


Now that step1.asp gets the user & pass variables and pass them to step2.asp page that way:


<html>
<!-- #include file="include/common.asp" -->
<!-- #include file="include/security.asp" -->
<head>
<meta http-equiv="Content-Language" content="tr">
<meta name="GENERATOR" content="Microsoft FrontPage 12.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1254">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<title>Login</title>
</head>

<body background="webimages/BGS/Gray.jpg" bgcolor="#D6D6DE" topmargin="2" leftmargin="35" oncontextmenu='return false' ondragstart='return false' onselectstart='return false'>
<form name="frm1" method="post" action="step2.asp">
<input type="hidden" name="_uid" id="_uid">
<input type="hidden" name="_pwd" id="_pwd">
</form>

<SCRIPT>
document.forms[0]._uid.value = document.getElementById("uid").value;
document.forms[0]._pwd.value = document.getElementById("pwd").value;
document.forms[0].submit();
</script>

</body>

</html>



After clicking on Enter on the login page, I receive the error for the step1.asp page:

Line:20
Char:1
Object Required
Code:0
Url=step1.asp

Line 20 is the beginning of the script.


Could not figure it out.
Any opinions/advise are wellcome.

whoisgregg

9:48 pm on Jun 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First, the included files may affect your line count in the actual code rendered by the browser. I'd make sure the line 20 you're looking at is the same as the line 20 the browser sees.

Second, I don't see any element with an ID of "uid" on the step2.asp page... I understand you're getting the error from the first page, but no matter what this approach won't work. Once step2.asp is loaded, JavaScript has no access to the elements from the step1.asp page.

Third, if the error is on step1.asp, what's line 20 on that page? Maybe there's something else going on there that's unrelated?

I believe I am confused about what's going on here anyway though, so any additional information you can share will be quite helpful. :)

subexpression

6:37 pm on Jun 4, 2010 (gmt 0)

10+ Year Member



fototex,

I'm confused which piece of code you posted belongs to what page.
Is the first part step1.asp?

<p>
Username:<span><input type="text" id="uid" name="uid" size="14"/> </span>
Pass:<span><input type="password" id="pwd" name="pwd" size="14"/></span>
<a onclick="return loginload()" href="#" class="btn">Enter</a>
...
function loginload() {
window.location="step1.asp";
}


If this code belongs in the step1.asp page, then why is your window.location sending you to step1.asp?

If it's not step1.asp, and some other page you haven't mentioned, then we're even more tangled up here.
One problem I see immediately is you're attempting to pass the values of "uid" and "pwd" inputs without an actual form submission on this mystery page. No values will be sent to step1.asp.

I suggest:
  • Create a form: <form name="loginform" action="step2.asp" method="post">...</form>
  • Place the <input> tags nested inside the <form></form> tags
  • Use a submit button <input type="submit" value="Enter" />


The "submit" type button has a special connection to it's parent <form>...it will activate window's location method through the form's action="" attribute. The URL, action="step2.asp", will receive the form information. Then, your form values for "uid" and "pwd" will officially be sent as POST variables...which can be read on the following page.

You cannot grab those post variables by "document.getElementById()" on the second page, because they are part of the first page's DOM (document object model). The Javascript engine has no idea what "uid" and "pwd" inputs are...they're gone.

You'll need to use ASP to extract the values of the post variables you sent.
Since this isn't an ASP forum, I will not post it here.
Javascript is incapable (as far as I know) of accessing the post array, since it is on the server, not in the client. This is why post is far more secure than using the GET method.