Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Script - getting a textboxes value 1

Status
Not open for further replies.

mtl77

Programmer
May 27, 2003
31
CA
Hey there,

I have an ASp page that i am using vbscript with to set some values to hidden input boxes and post the form. I am having trouble getting a value from a textbox using the document.textboxID.value in my vbscript and i can't figure out why. Any help would eb greatly appriciated.Thanks.

Here is the code!

<%@ Language=VBScript %>
<HTML>
<HEAD>
<%
user = document.txtLoginID.value
if user = "" then
else
sql="select URL from table where field ='"& user &"'"
oRs=cc.execute(sql)
url=oRs(0)
end if
%>
</HEAD>

<body>
<form id="Form2" name="LoginForm" method=post action="<=url%>" runat=server>

<INPUT id="txtLoginID" type="text" size="13" NAME="LoginID">

 
The problem is because you are trying to use client-side VBScript to obtain the value. You need the Server side syntax...
Code:
user = Request.Form("LoginID")
However. The URL you retrieve from the DB will not be used as the FORM's ACTION page until after you have submitted the page for the first time.

Tony
________________________________________________________________________________
 
Thanks Tony. Is there a way i can have the action set for the first submit of the form?

As you can probably tell i am not that familiar with ASP or vbscript so if i am doing this all wrong please let me know.

Kevin.
 
something like this perhaps...
Code:
<%  
user = Request.Form("LoginID")

If user <> "" Then    
  sql = "SELECT url FROM table WHERE field = '" & user & "'"
  oRs = cc.Execute(sql)
  url = oRs(0)
Else
  url = "default_page.asp"
End If     
%>
Out of interest, what exactly are you trying to do? There may be a better way of doing it but without knowing the details its a bit hard to comment.

Tony
________________________________________________________________________________
 
Basically I am using this page as a login page that takes a username and gets a specific url from a DB to post to another login page and automatically login to that page/application.

Originally i was trying it with C# and aspx but that proved to be very annoying and to much work for what i thought would be a pretty simple page.

Is there an easier way to do this?

Kevin
 
Here is the rest of the code.

<INPUT id="inpUser" type="hidden" size="1" name="operinit" value="<%=user%>">
<INPUT id="Submit1" type="submit" value="Login" name="Submit1">
 
how about submitting the LoginID to a second page that looks up the URL in the DB. That page can then automatically redirect to the new page [red](passing the LoginID in the querystring if necessary).[/red]

login.asp
Code:
<FORM action="login_action.asp" method="POST">
<INPUT type="TEXT" name="LoginID" />
<INPUT type="SUBMIT" />
</FORM>

login_action.asp
Code:
<%
strLoginID = Trim(Request.Form("LoginID"))

strLoginSQL = "SELECT url FROM table WHERE field = '" & strLoginID & "'"

Set oRs = cc.execute(strLoginSQL)

If NOT oRs.EOF Then
  url = oRs("url") [red]& "?LoginID=" & strLoginID[/red]
Else
  url = "Login.asp?error=true"
End If

Set oRs = Nothing

Response.Redirect url
%>

Tony
________________________________________________________________________________
 
I wanted to use the query string in the first place but i also have to send a password along wiht the username so i am a bit worried about security issues.

If i do use the querystring, how do i actually submit the form on the page that i am sendding the info to? I can get the values to fill the required fields on the form but i do not know how to submit it.

Thanks a million for all your help.
 
In that case you could store the username and password in Session variables.
login.asp
Code:
<FORM action="login_action.asp" method="POST">
<INPUT type="TEXT" name="LoginID" />
<INPUT type="PASSWORD" name="Password" />
<INPUT type="SUBMIT" />
</FORM>
login_action.asp
Code:
<%
Session("LoginID") = Trim(Request.Form("LoginID"))
Session("Password") = Trim(Request.Form("Password"))

strLoginSQL = "SELECT url FROM table WHERE field = '" & Session("LoginID") & "'"

Set oRs = cc.execute(strLoginSQL)

If NOT oRs.EOF Then
  url = oRs("url")
Else
  url = "Login.asp?error=true"
End If

Set oRs = Nothing

Response.Redirect url
%>
final [red]url[/red] login page
Code:
<HTML>
<HEAD>

</HEAD>
<BODY onLoad="document.myForm.submit();">
<FORM name="myForm" ACTION="myActionPage.asp">
<INPUT type="TEXT" name="LoginID" value="<%=Session("LoginID")%>" />
<INPUT type="PASSWORD" name="Password" value="<%=Session("Password")%>" />
</FORM>
</BODY>
</HTML>
Now this should work but it's not as elegant as doing all the "logging in" on the initial Login page. Why can't you process all the login work on that first login_action.asp page?

Tony
________________________________________________________________________________
 
The session variables worked like a charm. I just added code that you put in the last screen for final url page on the login_action page and set the Action of the form to a url session variable and it works great.

One more question though. Do i have to worry about killing the session variables?

Thanks a lot for your help.

Kevin.
 
The Session variables are only going be be present for the user session that created them - no-one else will be able to see them. They will automatically expire after the default Session timeout (either after inactivity or after the browser window is closed)

You can manually reset them if you wish by simply setting them to empty when you are finished with them:
Code:
Session("LoginID") = ""
Session("Password") = ""

Thanks for the star by the way :)

Tony
________________________________________________________________________________
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top