Link to home
Start Free TrialLog in
Avatar of tmurray22
tmurray22

asked on

ASP form, how to check post values

I have a form that creates checkboxes with asp and java script. How is the best way to check to see if it is
picking up the correct (checked )values. My post page is showing nothing.

Here is my form

<%@ Language = VBScript %>
<%Option Explicit%>
<%Response.Buffer = True%>
<%
if not(request.form("MName")="" or IsNull(request.form("MName"))) then
   Session("UserName") = request.form("MName")
end if
%>

<html>
<head>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>New Page 2</title>

<script language="javascript">
function toggleLesser(chbx)
{
     var wasChecked = chbx.checked;
     var thisName = chbx.value;
     var grpName = thisName.substr(0,6);
     var elemsInForm = chbx.form.elements
     var lim = elemsInForm.length;
     var iStopDisable = lim;
     for (var i=0;i<lim;i++)
     {
        var aChkBox = elemsInForm[i];
        var testName = aChkBox.value
        if (aChkBox.type && aChkBox.type=="checkbox" && testName.indexOf(grpName)==0)
        {
            if (testName == thisName)
            {
               iStopDisable = i;
            }
            else
            {
               aChkBox.checked = false;
            }
            if (i<iStopDisable) aChkBox.checked = wasChecked;
        }
     }
}
</script>
<%
dim  strDataPath, strConnectString, objConnection, strcmpname, strOS, strBuild, objRS, strSelected, oConn, oRs, MySQL, connect, myFile, tmp
Dim strUserName      'Holds the name of the user
dim arrayItems, i

strcmpname = Request.Form("cmpsub")
strOS = Request.Form("codeline")
strBuild = Request.Form("BldLabel")
strConnectString = "DRIVER={SQL Server};SERVER=PY1SPRODDEVWEB;DATABASE=CCWEBD;UID=ccadm;PWD=cc123cc"
if not IsObject("ojbConnection") then
      set objConnection=Server.CreateObject("ADODB.Connection")
      objConnection.ConnectionTimeout = 15
      objConnection.CommandTimeout =  10
      objConnection.Mode = 3 'adModeReadWrite
      if objConnection.state = 0 then
            objConnection.Open strConnectString
      end if
end if

sub makeCountry()
      if not isObject("objRS") then
            set objRS=Server.CreateObject("ADODB.RecordSet")
      end if
      if objRS.state <> 0 then
            objRS.close
      end if
      objRS.Open "SELECT DISTINCT cmpsub FROM cmpmap ORDER BY cmpsub",objConnection,3,3
      Response.Write("<option></option>" & VBCRLF )
      do while not objRS.EOF
            if objRS("cmpsub") = strcmpname then
                  strSelected = " Selected "
            else
                  strSelected = ""
            end if
            Response.Write("<option" & strSelected & ">" & objRS("cmpsub") & "</option>" & VBCRLF )
            objRS.MoveNext
      loop
      objRS.Close
      set objRS=Nothing
end sub

sub makeRegion()
      if strcmpname <> "" then
            if not isObject("objRS") then
                  set objRS=Server.CreateObject("ADODB.RecordSet")
            end if
            if objRS.state <> 0 then
                  objRS.close
            end if
            objRS.Open "SELECT DISTINCT codeline FROM cmpmap WHERE cmpsub = '" & strcmpname & "' ORDER BY codeline",objConnection,3,3
            if objRS.eof then
                  Response.Write("<option>No OS Found</option>")
            else
                  'Response.Write("<option>Select OS Now</option>" & VBCRLF )
                  do while not objRS.EOF
                        if objRS("codeline") = strOS then
                              strSelected = " Selected "
                        else
                              strSelected = ""
                        end if
                        Response.Write("<option" & strSelected & ">" & objRS("codeline") & "</option>" & VBCRLF )
                        objRS.MoveNext
                  loop
            end if
            objRS.Close
            set objRS=Nothing
      else
            Response.Write("<option>Select a Release First</option>")
      end if
end sub %>
<body onLoad="disableChecks('rad');">
<%
sub makeCity()
     if strOS <> "Select a Release First" AND  strOS <> "Select OS Now" AND strOS <>"" then
          if not isObject("objRS") then
               set objRS=Server.CreateObject("ADODB.RecordSet")
          end if
          if objRS.state <> 0 then
               objRS.close
          end if
          objRS.Open "Select Distinct bldlabel from cmpsub join cmpmap on cmpmap.multisub = cmpsub.cmpname and cmpmap.subcode = cmpsub.codeline where cmpmap.codeline =  '" & strOS & "' AND cmpsub.lastbld > 38 " ,objConnection,3,3
          'objRS.Open "Select DISTINCT bldlabel from cmpsub join cmpmap on cmpmap.multisub = cmpsub.cmpname and cmpmap.subcode = cmpsub.codeline where cmpmap.codeline =  '" & strOS & "'" ,objConnection,3,3
          'objRS.Open "Select max(BldLabel) as BldLabel from cmpsub join cmpmap on cmpmap.multisub = cmpsub.cmpname and cmpmap.subcode = cmpsub.codeline where cmpmap.codeline =  '" & strOS & "'GROUP by left(BldLabel,charindex('_',BldLabel)-1)" ,objConnection,3,3    
                if objRS.eof then
                Response.Write("<p>No Builds Found</p>")
          else
             
%>
<div name="theDiv" align="center">
  <table border="1" width="18%" id="table1">
  <tr><td width="97">

<%
           tmp = ""
               do while not objRS.EOF
                    if objRS("BldLabel") = strBuild then
                         strSelected = " Checked "
                    else
                         strSelected = ""
                    end if
                         
                         if Split(objRS("BldLabel"),"_")(0) <> tmp then
                              tmp = Split(objRS("BldLabel"),"_")(0)  
                         %>
                         <tr><td><font size="2" face="Century Gothic" color="#008080"><%=tmp%></font></td>
                         <%                                  
                         end if



%>
<tr><td><input type=checkbox name=<%=objRS("BldLabel")%> value="<%=objRS("BldLabel")%>"onClick="toggleLesser(this)"></td>
<td><%=objRS("BldLabel")%></td>
</tr>
<%
                    objRS.MoveNext
               loop
          end if%>
          </table>
</div>
<%
          objRS.Close
          set objRS=Nothing
     else
          'Response.Write("<p>Select an OS First</p>")
     end if
end sub

%>
<SCRIPT LANGUAGE=javascript>
<!--

function submitCountry(){
      var objForm = document.forms[0];
      objForm.elements['codeline'].selectedIndex=0;
      objForm.elements['bldLabel'].selectedIndex = 0;
      objForm.submit();
}
function submitRegion(){
      var objForm = document.forms[0];
      objForm.elements['bldlabel'].selectedIndex = 0;
      objForm.submit();
}

function submitForm(){
      var objForm = document.forms[0];
      objForm.action = "http://py1sproddevweb/scm/testpost3.asp"
      return true;
}
//-->
</SCRIPT>
</head>

<FORM action="testpost3.asp" method="POST" id="form1" name="rad" onSubmit="return checkValues(this)">
<p align="left">&nbsp;&nbsp;&nbsp;<img border="0" src="scmlogo.jpg" width="117" height="46" /></p><p align="center">
  <img border="0" src="multilogo.jpg" width="436" height="115" /></p><p align="center">
<font face="Century Gothic" size="2">Selected Sub_System
</font>&nbsp;&nbsp;&nbsp;<font face="Century Gothic" size="2" color="#008080"><%response.write request.form("cmpsub")%>
</font>
<font color="#008080">
<br />
</font>&nbsp;&nbsp;&nbsp;<font face="Century Gothic" size="2">Selected Codeline
</font>&nbsp;&nbsp;&nbsp;<font face="Century Gothic" size="2" color="#008080"><%response.write request.form("codeline")%>
</font>
</p>
<p align="center">&nbsp;&nbsp;&nbsp;<font face="Century Gothic" size="2"><font color="#808080">Please Select
</font><b>Build Label(s) </b></font>
</p>
<p align="center">&nbsp;&nbsp;&nbsp;<%call makeCity%>
</p>
<input type=hidden name=hcodeline value=<% = Request.Form("Codeline") %>>
<input type=hidden name=hcmpsub value=<% = Request.Form("cmpsub") %>>
<p align="center">
<p align="center"><INPUT type="submit" value="Submit" id="submit1" name="submit1" style="border-style: inset; border-width: 1px" /></p>
</p>
</FORM>
<script>
function checkValues(frm){
if (("<% =Request.Form("cmpsub") %>"=="dm3ssp")) frm.action="adfield.asp";
else frm.action="testpost3.asp";
return true;
}
</script>
</body>
<%
objConnection.Close
set objConnection = Nothing
%></html>
Avatar of SquareHead
SquareHead

Maybe put this on the form handler page...

<%
dim iFormItem
For iFormItem = 1 to Request.Form.Count %>
<%= Request.Form.Key(iFormItem) %> = <%= Request.Form.Item(iFormItem) %><br>
<%  Next %>
Avatar of tmurray22

ASKER

as is ?

or do I replace IformItem with my variable "bldLabel"
Okay that show the values correctly
When i try to use
<%= Request.Form.Item(strBuild) %>

in another part of the page I get an error

Request object error 'ASP 0105 : 80004005'

Index out of range

/scm/adfield.asp, line 67

An array index is out of range.



ASKER CERTIFIED SOLUTION
Avatar of SquareHead
SquareHead

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
Request.Form("BldLabel") is not returning a value,

I did this
<%
dim iFormItem
For strBuild = 1 to Request.Form.Count %>
<%= Request.Form.Key(strBuild) %> = <%= Request.Form.Item(strBuild) %><br>
<%  Next %>


which returns this:
DM3DSP_HMP_2.0_12 = DM3DSP_HMP_2.0_12

This is the correct check box

I guess what I am asking is what is the relationship between that statement and <%= Request.Form.Item(strBuild) %>


Okay, the code read objrs("BldLabel") which was returning the value for every checkbox. I changed to
name=bldlabel and everything is working.

thanks
tmurray22