ljhodgett
asked on
issue with form using classic asp.
Hi,
I apologize in advance as I'm new to asp as i'm usually a windows forms developer. I've got the following code: -
<form method="get" action="testcopy.asp">
Serial No: <input type="text" name="fname" /><br />
Model No: <input type="text" name="lname" /><br />
<input type="submit" value="Submit" />
</form>
<%
IF NOT Request.QueryString("fName ")<>"" THEN
%><text><font color=red><%response.Write ("Serial Number is Missing") %></font></text><br /><%
END IF
IF NOT Request.QueryString("lName ")<>"" THEN
%><text><font color=red><%response.Write ("Model Number is Missing") %></font></text><%
END IF
%>
When the page loads for the first it comes up with both Serial Number is Missing and Model Number is Missing which I presume it will do with the above code as both text boxes are empty when the page loads. How do I make it so that it does not show when the page loads and does when the submit button is pressed.
Many Thanks
Lee
I apologize in advance as I'm new to asp as i'm usually a windows forms developer. I've got the following code: -
<form method="get" action="testcopy.asp">
Serial No: <input type="text" name="fname" /><br />
Model No: <input type="text" name="lname" /><br />
<input type="submit" value="Submit" />
</form>
<%
IF NOT Request.QueryString("fName
%><text><font color=red><%response.Write
END IF
IF NOT Request.QueryString("lName
%><text><font color=red><%response.Write
END IF
%>
When the page loads for the first it comes up with both Serial Number is Missing and Model Number is Missing which I presume it will do with the above code as both text boxes are empty when the page loads. How do I make it so that it does not show when the page loads and does when the submit button is pressed.
Many Thanks
Lee
ASKER
Hi,
I've put it in the page as follows: -
<!--#include file="../../config.inc.asp "-->
<%
'* System admin form, online access to Line Configurator
'* This page allows users with admin permissions to reconfigure the equipment
'* that is used on a specific production line
'check login information
If session("username") = "" and request.querystring("viewo nly")="" Then ' if not logged in at all
Response.Redirect "/test/loginscript.asp?Mes sageNo=1&W hereURL=" & request.servervariables("U RL")
end if
if Session("bAdmin")<>"True" and request.querystring("viewo nly")="" then
response.write("Insufficie nt permission level. User must be an admin to perform Line Configuration")
response.end
end if
if not (Session("LocalUserID") = 13 OR Session("LocalUserID") = 79) then
response.write("Insufficie nt permission level. Only Lee & Rob have permission to view form")
response.end
end if
bIgnoreTab=True
%>
<html>
<head>
<title>Test Engineering - Register Test copy</title>
<link rel="stylesheet" href="/basestyle.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%
Fucntion checkForm ()
IF NOT Request.QueryString("fName ")<>"" THEN
%><text><font color=red><%response.Write ("Serial Number is Missing") %></font></text><br /><%
END IF
IF NOT Request.QueryString("lName ")<>"" THEN
%><text><font color=red><%response.Write ("Model Number is Missing") %></font></text><%
END IF
End Function
%>
</head>
<%
Dim Conn, sqlRecordSet,cLineID
set Conn = Server.CreateObject("ADODB .Connectio n")
Conn.open global_TestServer
Conn.CommandTimeOut=0
Set rs = Server.CreateObject("ADODB .RecordSet ") ' set recordset object
rs.CursorLocation = 3 ' use client cursor location as there will be lots of scanning
cQueryString="Select SerialNumber, ModelNumber, convert(varchar(20),Last_T ested,3) + ' ' + convert(varchar(20),Last_T ested,108) as Last_Tested, Username FROM dbo.TestCopy left JOIN Users ON dbo.TestCopy.Tested_By = Users.LocalUserID order by ModelNumber"
rs.Open cQueryString,Conn, 2, 1 ' execute query
%>
<table width = "100%">
<tr>
<td><center><font size="4"><B>Test Copy Registration</B></font></c enter></td >
</tr>
<tr>
<td><center><font size="3">This webpage shows all current registered test copies within test control</font></center></t d>
</tr>
</table>
</br>
<table border = 0 cellspacing = 1 width = "100%">
<tr>
<td width="17%"><center><font size="2"><B>Test Copy Serial Number</B></font></center> </td>
<td width="43%"><center><font size="2"><B>Test Copy Model Number</B></font></center> </td>
<td width="17%"><center><font size="2"><B>Last Tested</B></font></center> </td>
<td width="20%"><center><font size="2"><B>Tested By</B></font></center></td >
</tr>
<%
do while not RS.eof
%>
<tr bgcolor="lightblue">
<td><Left><font size="2"><%response.write RS("SerialNumber")%> </font></c enter></td >
<td><center><font size="2"><%response.write RS("ModelNumber")%></font> </center>< /td>
<td><center><font size="2"><%response.write RS("Last_Tested")%></font> </center>< /td>
<td><center><font size="2"><%response.write RS("Username")%></font></c enter></td >
</tr>
<%
RS.movenext
loop
%>
</table>
<form method="get" action="testcopy.asp" >
<center>
<table border =1 >
<tr>
<td>
<center><font color ="blue" >Register New Test Copy</font></center>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
Serial No:
</td>
<td>
<input type="text" name="fname" />
</td>
</tr>
<tr>
<td>
Model No:
</td>
<td>
<input type="text" name="lname" size ="80" />
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
<br />
</form>
<BR>
<HR/>
<%
rs.Close
set rs = nothing
Conn.Close
set Conn = nothing
%>
</BODY>
</html>
But it comes up with an error saying: -
Microsoft VBScript compilation error '800a0400'
Expected statement
/test/admin/ManagerPanel/t estcopy.in c.asp, line 45
End Function
Many Thanks for your help.
Lee
I've put it in the page as follows: -
<!--#include file="../../config.inc.asp
<%
'* System admin form, online access to Line Configurator
'* This page allows users with admin permissions to reconfigure the equipment
'* that is used on a specific production line
'check login information
If session("username") = "" and request.querystring("viewo
Response.Redirect "/test/loginscript.asp?Mes
end if
if Session("bAdmin")<>"True" and request.querystring("viewo
response.write("Insufficie
response.end
end if
if not (Session("LocalUserID") = 13 OR Session("LocalUserID") = 79) then
response.write("Insufficie
response.end
end if
bIgnoreTab=True
%>
<html>
<head>
<title>Test Engineering - Register Test copy</title>
<link rel="stylesheet" href="/basestyle.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%
Fucntion checkForm ()
IF NOT Request.QueryString("fName
%><text><font color=red><%response.Write
END IF
IF NOT Request.QueryString("lName
%><text><font color=red><%response.Write
END IF
End Function
%>
</head>
<%
Dim Conn, sqlRecordSet,cLineID
set Conn = Server.CreateObject("ADODB
Conn.open global_TestServer
Conn.CommandTimeOut=0
Set rs = Server.CreateObject("ADODB
rs.CursorLocation = 3 ' use client cursor location as there will be lots of scanning
cQueryString="Select SerialNumber, ModelNumber, convert(varchar(20),Last_T
rs.Open cQueryString,Conn, 2, 1 ' execute query
%>
<table width = "100%">
<tr>
<td><center><font size="4"><B>Test Copy Registration</B></font></c
</tr>
<tr>
<td><center><font size="3">This webpage shows all current registered test copies within test control</font></center></t
</tr>
</table>
</br>
<table border = 0 cellspacing = 1 width = "100%">
<tr>
<td width="17%"><center><font size="2"><B>Test Copy Serial Number</B></font></center>
<td width="43%"><center><font size="2"><B>Test Copy Model Number</B></font></center>
<td width="17%"><center><font size="2"><B>Last Tested</B></font></center>
<td width="20%"><center><font size="2"><B>Tested By</B></font></center></td
</tr>
<%
do while not RS.eof
%>
<tr bgcolor="lightblue">
<td><Left><font size="2"><%response.write RS("SerialNumber")%>
<td><center><font size="2"><%response.write RS("ModelNumber")%></font>
<td><center><font size="2"><%response.write RS("Last_Tested")%></font>
<td><center><font size="2"><%response.write RS("Username")%></font></c
</tr>
<%
RS.movenext
loop
%>
</table>
<form method="get" action="testcopy.asp" >
<center>
<table border =1 >
<tr>
<td>
<center><font color ="blue" >Register New Test Copy</font></center>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
Serial No:
</td>
<td>
<input type="text" name="fname" />
</td>
</tr>
<tr>
<td>
Model No:
</td>
<td>
<input type="text" name="lname" size ="80" />
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
<br />
</form>
<BR>
<HR/>
<%
rs.Close
set rs = nothing
Conn.Close
set Conn = nothing
%>
</BODY>
</html>
But it comes up with an error saying: -
Microsoft VBScript compilation error '800a0400'
Expected statement
/test/admin/ManagerPanel/t
End Function
Many Thanks for your help.
Lee
function in the opening function declaration is spelled wrong.. that might be the problem....
ASKER
lol, I've sorted that one out but when I click submit it does not print serial number not found or model number not found with the following code:-
<!--#include file="../../config.inc.asp "-->
<%
'* System admin form, online access to Line Configurator
'* This page allows users with admin permissions to reconfigure the equipment
'* that is used on a specific production line
'check login information
If session("username") = "" and request.querystring("viewo nly")="" Then ' if not logged in at all
Response.Redirect "/test/loginscript.asp?Mes sageNo=1&W hereURL=" & request.servervariables("U RL")
end if
if Session("bAdmin")<>"True" and request.querystring("viewo nly")="" then
response.write("Insufficie nt permission level. User must be an admin to perform Line Configuration")
response.end
end if
if not (Session("LocalUserID") = 13 OR Session("LocalUserID") = 79) then
response.write("Insufficie nt permission level. Only Lee & Rob have permission to view form")
response.end
end if
bIgnoreTab=True
%>
<html>
<head>
<title>Test Engineering - Register Test copy</title>
<link rel="stylesheet" href="/basestyle.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%
Function checkForm ()
IF NOT Request.QueryString("fName ")<>"" THEN
%><text><font color=red><%response.Write ("Serial Number is Missing") %></font></text><br /><%
END IF
IF NOT Request.QueryString("lName ")<>"" THEN
%><text><font color=red><%response.Write ("Model Number is Missing") %></font></text><%
END IF
End Function
%>
</head>
<%
Dim Conn, sqlRecordSet,cLineID
set Conn = Server.CreateObject("ADODB .Connectio n")
Conn.open global_TestServer
Conn.CommandTimeOut=0
Set rs = Server.CreateObject("ADODB .RecordSet ") ' set recordset object
rs.CursorLocation = 3 ' use client cursor location as there will be lots of scanning
cQueryString="Select SerialNumber, ModelNumber, convert(varchar(20),Last_T ested,3) + ' ' + convert(varchar(20),Last_T ested,108) as Last_Tested, Username FROM dbo.admin_TestCopy_Registe r left JOIN dbo.admin_Users ON dbo.admin_TestCopy_Registe r.Tested_B y = dbo.admin_Users.LocalUserI D order by ModelNumber"
rs.Open cQueryString,Conn, 2, 1 ' execute query
%>
<table width = "100%">
<tr>
<td><center><font size="4"><B>Test Copy Registration</B></font></c enter></td >
</tr>
<tr>
<td><center><font size="3">This webpage shows all current registered test copies within test control</font></center></t d>
</tr>
</table>
</br>
<table border = 0 cellspacing = 1 width = "100%">
<tr>
<td width="17%"><center><font size="2"><B>Test Copy Serial Number</B></font></center> </td>
<td width="43%"><center><font size="2"><B>Test Copy Model Number</B></font></center> </td>
<td width="17%"><center><font size="2"><B>Last Tested</B></font></center> </td>
<td width="20%"><center><font size="2"><B>Tested By</B></font></center></td >
</tr>
<%
do while not RS.eof
%>
<tr bgcolor="lightblue">
<td><Left><font size="2"><%response.write RS("SerialNumber")%> </font></c enter></td >
<td><center><font size="2"><%response.write RS("ModelNumber")%></font> </center>< /td>
<td><center><font size="2"><%response.write RS("Last_Tested")%></font> </center>< /td>
<td><center><font size="2"><%response.write RS("Username")%></font></c enter></td >
</tr>
<%
RS.movenext
loop
%>
</table>
<form method="get" action="testcopy.asp" onsubmit="return checkForm()" >
<center>
<table border =1 >
<tr>
<td>
<center><font color ="blue" >Register New Test Copy</font></center>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
Serial No:
</td>
<td>
<input type="text" name="fname" />
</td>
</tr>
<tr>
<td>
Model No:
</td>
<td>
<input type="text" name="lname" size ="80" />
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
<br />
</form>
<BR>
<HR/>
<%
rs.Close
set rs = nothing
Conn.Close
set Conn = nothing
%>
</BODY>
</html>
Best Regards
Lee
<!--#include file="../../config.inc.asp
<%
'* System admin form, online access to Line Configurator
'* This page allows users with admin permissions to reconfigure the equipment
'* that is used on a specific production line
'check login information
If session("username") = "" and request.querystring("viewo
Response.Redirect "/test/loginscript.asp?Mes
end if
if Session("bAdmin")<>"True" and request.querystring("viewo
response.write("Insufficie
response.end
end if
if not (Session("LocalUserID") = 13 OR Session("LocalUserID") = 79) then
response.write("Insufficie
response.end
end if
bIgnoreTab=True
%>
<html>
<head>
<title>Test Engineering - Register Test copy</title>
<link rel="stylesheet" href="/basestyle.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%
Function checkForm ()
IF NOT Request.QueryString("fName
%><text><font color=red><%response.Write
END IF
IF NOT Request.QueryString("lName
%><text><font color=red><%response.Write
END IF
End Function
%>
</head>
<%
Dim Conn, sqlRecordSet,cLineID
set Conn = Server.CreateObject("ADODB
Conn.open global_TestServer
Conn.CommandTimeOut=0
Set rs = Server.CreateObject("ADODB
rs.CursorLocation = 3 ' use client cursor location as there will be lots of scanning
cQueryString="Select SerialNumber, ModelNumber, convert(varchar(20),Last_T
rs.Open cQueryString,Conn, 2, 1 ' execute query
%>
<table width = "100%">
<tr>
<td><center><font size="4"><B>Test Copy Registration</B></font></c
</tr>
<tr>
<td><center><font size="3">This webpage shows all current registered test copies within test control</font></center></t
</tr>
</table>
</br>
<table border = 0 cellspacing = 1 width = "100%">
<tr>
<td width="17%"><center><font size="2"><B>Test Copy Serial Number</B></font></center>
<td width="43%"><center><font size="2"><B>Test Copy Model Number</B></font></center>
<td width="17%"><center><font size="2"><B>Last Tested</B></font></center>
<td width="20%"><center><font size="2"><B>Tested By</B></font></center></td
</tr>
<%
do while not RS.eof
%>
<tr bgcolor="lightblue">
<td><Left><font size="2"><%response.write RS("SerialNumber")%>
<td><center><font size="2"><%response.write RS("ModelNumber")%></font>
<td><center><font size="2"><%response.write RS("Last_Tested")%></font>
<td><center><font size="2"><%response.write RS("Username")%></font></c
</tr>
<%
RS.movenext
loop
%>
</table>
<form method="get" action="testcopy.asp" onsubmit="return checkForm()" >
<center>
<table border =1 >
<tr>
<td>
<center><font color ="blue" >Register New Test Copy</font></center>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
Serial No:
</td>
<td>
<input type="text" name="fname" />
</td>
</tr>
<tr>
<td>
Model No:
</td>
<td>
<input type="text" name="lname" size ="80" />
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
<br />
</form>
<BR>
<HR/>
<%
rs.Close
set rs = nothing
Conn.Close
set Conn = nothing
%>
</BODY>
</html>
Best Regards
Lee
let's try moving this to the onClick event for the submit button rather than onSubmit.
remove the onSubmit from the form and add onClick"checkForm()" to the submit button. I will test here too while are are testing there.
remove the onSubmit from the form and add onClick"checkForm()" to the submit button. I will test here too while are are testing there.
ASKER
Still no joy i'm afraid. Thanks for trying your end too.
Lee
Lee
no worries... testing for a solution as we speak
theoretically th is should work but I cannot seem to figure out why... maybe someone else can chime in and show us both where we are going wrong? I simplied your page just to make it easier for me to test..
<html>
<head>
<SCRIPT LANGUAGE="VBScript">
<!---
Sub testbutton_OnClick()
if (document.formtest.fname.v alue="") and (document.formtest.lname.v alue="") THEN
msgbox("test")
<text><font color=red><%response.Write ("Serial Number is Missing")</font></text><br />
Exit Sub
Else
document.formtest.submit
END IF
End Sub
<---
</script>
</head>
<body>
<form method="post" name = "formtest" action="testcopy.asp" >
<center><font color ="blue" >Register New Test Copy</font></center>
Serial No:
<input type="text" name="fname" />
Model No:
<input type="text" name="lname" size ="80" />
<INPUT TYPE="Button" NAME="testbutton" VALUE="Submit">
</form>
</body>
</html>
<html>
<head>
<SCRIPT LANGUAGE="VBScript">
<!---
Sub testbutton_OnClick()
if (document.formtest.fname.v
msgbox("test")
<text><font color=red><%response.Write
Exit Sub
Else
document.formtest.submit
END IF
End Sub
<---
</script>
</head>
<body>
<form method="post" name = "formtest" action="testcopy.asp" >
<center><font color ="blue" >Register New Test Copy</font></center>
Serial No:
<input type="text" name="fname" />
Model No:
<input type="text" name="lname" size ="80" />
<INPUT TYPE="Button" NAME="testbutton" VALUE="Submit">
</form>
</body>
</html>
it appears your mixing javascript with ASP
I would do something like this
its javascript and allows you to do more clientside validations such as is the serial number > 1 or length > 5 etc...
<html>
<head>
<SCRIPT LANGUAGE="Javascript">
<!---
function validate(){
if (document.formtest.fname.v alue="") ||(document.formtest.lname .value="") {
alert ("Serial Number is Missing");
return false;
}
return true;
}
</script>
</head>
<body>
<form method="post" name = "formtest" action="testcopy.asp" onsubmit="return validate(this)">
<center><font color ="blue" >Register New Test Copy</font></center>
Serial No:
<input type="text" name="fname" />
Model No:
<input type="text" name="lname" size ="80" />
<INPUT TYPE="Button" NAME="testbutton" VALUE="Submit">
</form>
</body>
</html>
I would do something like this
its javascript and allows you to do more clientside validations such as is the serial number > 1 or length > 5 etc...
<html>
<head>
<SCRIPT LANGUAGE="Javascript">
<!---
function validate(){
if (document.formtest.fname.v
alert ("Serial Number is Missing");
return false;
}
return true;
}
</script>
</head>
<body>
<form method="post" name = "formtest" action="testcopy.asp" onsubmit="return validate(this)">
<center><font color ="blue" >Register New Test Copy</font></center>
Serial No:
<input type="text" name="fname" />
Model No:
<input type="text" name="lname" size ="80" />
<INPUT TYPE="Button" NAME="testbutton" VALUE="Submit">
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<%
Fucntion checkForm ()
IF NOT Request.QueryString("fName
%><text><font color=red><%response.Write
END IF
IF NOT Request.QueryString("lName
%><text><font color=red><%response.Write
END IF
End Function
%>
Your HTML would look like this:
<form method="get" action="testcopy.asp" onsubmit="return checkForm()" >
Serial No: <input type="text" name="fname" /><br />
Model No: <input type="text" name="lname" /><br />
<input type="submit" value="Submit" />
</form>