//flex table opened by JP

Click to See Complete Forum and Search --> : javascript within asp - 2nd run problem


doowle
09-09-2002, 02:57 AM
Hi,

Hope you can help me. I have an app that starts out with aspen.asp which just contains an iframe aspen01.asp. On this page, the user logs in and if authenticated moves on to aspen02.asp. If not authenticated, error messagebox pops up and user can try again. This was working fine.

I had to add a javascript function in the middle of my asp authentication code to open aspen02.asp full screen though, and this is where I ran into trouble. The first time it runs it always runs fine. If user fails to authenticate, throws error messagebox. If user successfully authenticates, it opens aspen02.asp fullscreen.

But when the window launches fullscreen, it still leaves the original login window open underneath. I wouldn't care, except that if someone logs in, gets to aspen02.asp does their stuff and logs out, if someone tries to reuse that original login window that was left underneath and fails to authenticate, although it throws the error messagebox, it also launches aspen02.asp again -- regardless of whether user authentication was successful or not --.

Please help! I have been at this all weekend, and my boss wants it in the morning. I am panicking now...

I am guessing it has to do with the if not rs.eof part, but nothing I have tried to resolve it is fixing the problem *sob*

This is my sourcecode for aspen01.asp (aspen.asp contains nothing but the iframe tag for aspen01.asp):

<!--#include file="source/include/common.asp" -->
<%
If UCase(Request.ServerVariables("REQUEST_METHOD")) = "POST" Then
' declare variables
intMEPS = Request("cboMEPS")
strProctor = Trim(Request("txtProctor"))
strPassword = Trim(Request("txtPassword"))


' check to ensure the supplied authentication information is valid
strSQL = "SELECT * " & _
"FROM tblProctor " & _
"WHERE LastName = '" & formatString(strProctor, 1) & "' " & _
"AND Password = '" & formatString(strPassword, 1) & "' " & _
"AND Deleted = 'N'"
Set rs = objConn.Execute(strSQL)

' if it is retrieve and store pertinent information into the users session
If Not rs.EOF Then
Session.Timeout = 120
Session("PID") = rs("PID")
Session("ProctorName") = rs("FirstName") & " " & rs("LastName")
intLogins = rs("Logins") + 1

strSQL = "SELECT * " & _
"FROM tblMEPS " & _
"WHERE MID = " & intMEPS & ""
Set rs = objConn.Execute(strSQL)
Session("MID") = intMEPS
Session("MEPSName") = rs("Name")

'store last login information, update logins
strSQL = "UPDATE tblProctor " & _
"SET LastLogin = '" & Now() & "', " & _
"Logins = " & intLogins & " " & _
"WHERE LastName = '" & formatString(strProctor, 1) & "' " & _
"AND Password = '" & formatString(strPassword, 1) & "'"
Set cmd = objConn.Execute(strSQL)
Set cmd = Nothing
%>
<script language="JavaScript">
window.open('aspen02.asp', '', 'fullscreen=yes, scrollbars=auto')
</script>
<%
Else
' return an error if the user information was not found or not valid
Call returnError("User information not found...", 1)
%>
<script language="JavaScript">
window.location.reload()
</script>
<%

End If

End If

' retrieve the list of MEPS to populate the drop menu
strSQL = "SELECT * " & _
"FROM tblMEPS " & _
"ORDER BY Name"
Set rs = objConn.Execute(strSQL)

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>

<title><%=Application("Title")%></title>
<link rel="stylesheet" href="source/style/default.css" type="text/css">
<script LANGUAGE="JavaScript">
// function used to handle a variety of actions
function handleAction(strAction)
{
// used when the submit button has been clicked
if(strAction == 'validateForm')
{
// ensure all required fields were satisfied
if(document.frm.cboMEPS.value != ''
&& document.frm.txtProctor.value != ''
&& document.frm.txtPassword.value != '')
{
// check to ensure the text fields do not soely contain a number
if(isNaN(document.frm.txtProctor.value))
// && isNaN(document.frm.txtPassword.value))
{
document.frm.submit();
}
else
{
alert('A value supplied for one or more field(s) appears to be invalid...');
}
}
else
{
alert('At least one required field was left blank...');
}
}

}

</script>

</head>

<body class="body">

<table height=100% align="center"><tr><td align="center" valign="top" class="table" >

<br><br><br>
<br><p align="center"><font size=7><strong>ASPEN</strong></font><br><br>
</p>
<br><br >
<form name="frm" method="post" action="<%=Request.ServerVariables("SCRIPT_NAME")%>">
<table width="100%" border="0" align="left" cellspacing="10"
style="font-size: 8pt; font-family: arial, Verdana, sans-serif; font-weight: bold">
<tr>
<td height="33">MEPS Name:<br>
<select name="cboMEPS" id="cboMEPS" size="1">
<option></option>
<%
' loop through the MEPS recordset writing select option for each value
While Not rs.EOF
Response.Write("<option value='" & rs("MID") & "'>" & rs("Name") & "</option>")
rs.MoveNext
WEND
%> </select> </td>
</tr>
<tr>
<td height="33"> Proctor Last Name:<br>
<input name="txtProctor" type="text" id="txtProctor" size="35"
maxlength="35"> </td>
</tr>
<tr>
<td height="33">Password:<br>
<input name="txtPassword" type="password" id="txtPassword" size="6"
maxlength="6"> </td>
</tr>
<tr>
<td width="193"></td>
<td width="381"> </td>
</tr>
</table>
<tr><td valign="bottom" align="left">
<input name="btnSubmit" type="button" id="btnSubmit" value="Submit" onClick="handleAction('validateForm')">
<input name="btnReset" type="reset" id="btnReset" value="Reset">


</td>

<td valign="bottom" align="right"><font size=1, style="normal"><a href="default.asp">Admin Utilities</a></font></td>
</tr>
</table>
</form>

</body>
</html>

Karifan
09-10-2002, 01:18 AM
It could be the rs.EOF part, but I am thinking.
1)why do you have to open aspen2 in a new window?
2)You could test for if login success then close original window
3)You might have to set a new variable, you have to reset the part right before the javascript that opens aspen 2.
It seems that part stores the info in the database, but keeps a reference of it somewhere that makes aspen 2 open, because the user had already logged in once before that successfully.

I am no hardcore vbscript programmer, I took a measly 1 month course. What is aspen2 or 1, I have heard of it somewhere but can not remember for some reason.

Lets discuss this whole topic in hope we can find a solution. usually when you reflect on it with an outsider, just thinking about it from another angle helps.

One last shot is another test with in the rs.EOF test, If NOT rs.EOF and if session <1
then this,
other wise
refresh the page and ask them to relog? no?

hmmmmm


let me know if anything I said makes sense

doowle
09-10-2002, 02:29 AM
I have to open it in a new window because they want it to be fullscreen once the original login by the test proctor occurs, so the test-taker has no access to any menus during the test.

I tried closing the original login window, but it requires confirmation to close (browser trying to close window, is this ok type of popup window) which isn't acceptable to my boss.

aspen is an acronym for something I can't remember, isn't that terrible? It's some kind of special programs aptitude/assessment test.

I will try adding the if session<1 then... and see what happens, that actually sounds like it might work. Won't have a chance to do it until tomorrow night though.

Thanks for the brainstorming!! I wasn't getting anywhere with it anymore. Starts to look like alphabet soup after a while.

Karifan
09-10-2002, 08:54 AM
Now the thing is you have to reset that session variable too. so for instance if session is <1 then
session = 1 and do the the part where it creates the recordset and opens aspen 2 in a new window.
otherwise Do nothing(which is fine, security is more important than user comfort in this instance)
And display a message that states the user has to close the window and start over!!!

I think this would solve it temporarily, till you can come up with something much more effective.

GL, let me know how it works

doowle
09-15-2002, 08:37 PM
I ended up going the lazy way - if the user is using Netscape, I close the original window (because Netscape doesn't ask for confirmation to close). If the user is using Explorer, I just reload the login window instead - because if I close it there is a confirmation window that pops up but if I refresh it is transparent to the user.

Where before I just had


<script language="JavaScript">
window.open('aspen02.asp', '', 'fullscreen=yes, scrollbars=auto')
</script>



I replaced it with

<script language="JavaScript">
//netscape only
if (navigator.appName.indexOf("Netscape") != -1) {
window.open('aspen02.asp','', 'fullscreen=yes, scrollbars=auto, resizable=no');
// msgWindow.location.href ='aspen02.asp';
if (Window.opener == null) Window.opener = self;
}
else
// explorer
window.open('aspen02.asp','', 'fullscreen=yes, scrollbars=auto, resizable=no');
window.location.reload('aspen.asp');
</script>


then I just throw the line

opener.close();

in the page that opens full screen - which closes the login screen if the user is in Netscape.