• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 322
  • Last Modified:

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
0
ljhodgett
Asked:
ljhodgett
1 Solution
 
lharrispvCommented:
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>
0
 
ljhodgettAuthor Commented:
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

0
 
lharrispvCommented:
function in the opening function declaration is spelled wrong.. that might be the problem....
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ljhodgettAuthor Commented:
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
0
 
lharrispvCommented:
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.
0
 
ljhodgettAuthor Commented:
Still no joy i'm afraid. Thanks for trying your end too.

Lee
0
 
lharrispvCommented:
no worries... testing for a solution as we speak
0
 
lharrispvCommented:
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>
0
 
rg20Commented:
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>
0
 
harris9999Commented:
You could do a check to see if the form was actually submitted.  
I assume the form is being submitted to the page itself.
So first check if the form has been submitted then do the validation

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



<form method="get" action="testcopy.asp">
Serial No: <input type="text" name="fname" /><br />
Model No: <input type="text" name="lname" /><br />
<input type="hidden" name="frmSubmit" value="1" /><
<input type="submit" value="Submit" />
</form>


<%
IF request.querystring("frmSubmit")=1 then
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 IF
%>
 
 
 
<form method="get" action="testcopy.asp">
Serial No: <input type="text" name="fname" /><br />
Model No: <input type="text" name="lname" /><br />
<input type="hidden" name="frmSubmit" value="1" /><
<input type="submit" value="Submit" />
</form>

Open in new window

0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now