Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ASP form, how to check post values

Posted on 2006-04-27
7
Medium Priority
?
291 Views
Last Modified: 2008-03-06
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>
0
Comment
Question by:tmurray22
  • 5
  • 2
7 Comments
 
LVL 18

Expert Comment

by:SquareHead
ID: 16558656
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 %>
0
 

Author Comment

by:tmurray22
ID: 16559202
as is ?

or do I replace IformItem with my variable "bldLabel"
0
 

Author Comment

by:tmurray22
ID: 16559632
Okay that show the values correctly
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:tmurray22
ID: 16559670
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.



0
 
LVL 18

Accepted Solution

by:
SquareHead earned 2000 total points
ID: 16562918
This is in your code:
strBuild = Request.Form("BldLabel")

so saying
<%= Request.Form.Item(strBuild) %>

is like saying
<%= Request.Form.Item(Request.Form("BldLabel")) %>

Maybe I'm missing something, but if this is correct, I guess you need to make sure Request.Form("BldLabel") is returning a value, and then you'd have to have a form element named whatever that value is... seems awkward to me.
0
 

Author Comment

by:tmurray22
ID: 16564747
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) %>


0
 

Author Comment

by:tmurray22
ID: 16570739
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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question