Link to home
Start Free TrialLog in
Avatar of ljhodgett
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
Avatar of lharrispv
lharrispv
Flag of United States of America image

Put the code into a function in the head of the html page and then an onSubmit to the form

<%
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
%>

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>
Avatar of ljhodgett
ljhodgett

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("viewonly")=""  Then                                    ' if not logged in at all      
    Response.Redirect "/test/loginscript.asp?MessageNo=1&WhereURL=" & request.servervariables("URL")    
end if

if Session("bAdmin")<>"True" and request.querystring("viewonly")=""  then
      response.write("Insufficient 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("Insufficient 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.Connection")
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_Tested,3) + ' ' + convert(varchar(20),Last_Tested,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></center></td>
    </tr>
    <tr>
        <td><center><font size="3">This webpage shows all current registered test copies within test control</font></center></td>
    </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")%>&nbsp;</font></center></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></center></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/testcopy.inc.asp, line 45

End Function

Many Thanks for your help.
Lee

function in the opening function declaration is spelled wrong.. that might be the problem....
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("viewonly")=""  Then                                    ' if not logged in at all      
    Response.Redirect "/test/loginscript.asp?MessageNo=1&WhereURL=" & request.servervariables("URL")    
end if

if Session("bAdmin")<>"True" and request.querystring("viewonly")=""  then
      response.write("Insufficient 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("Insufficient 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.Connection")
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_Tested,3) + ' ' + convert(varchar(20),Last_Tested,108)  as Last_Tested, Username FROM dbo.admin_TestCopy_Register left JOIN dbo.admin_Users      ON  dbo.admin_TestCopy_Register.Tested_By = dbo.admin_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></center></td>
    </tr>
    <tr>
        <td><center><font size="3">This webpage shows all current registered test copies within test control</font></center></td>
    </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")%>&nbsp;</font></center></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></center></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
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.
Still no joy i'm afraid. Thanks for trying your end too.

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.value="") and (document.formtest.lname.value="") 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>
Avatar of rg20
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.value="") ||(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>
ASKER CERTIFIED SOLUTION
Avatar of harris9999
harris9999
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial