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-Langua ge" 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=PY1SPRODDEV WEB;DATABA SE=CCWEBD; UID=ccadm; PWD=cc123c c"
if not IsObject("ojbConnection") then
set objConnection=Server.Creat eObject("A DODB.Conne ction")
objConnection.ConnectionTi meout = 15
objConnection.CommandTimeo ut = 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.Rec ordSet")
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.Rec ordSet")
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>S elect 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>Se lect 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.Rec ordSet")
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" )%>"onClic k="toggleL esser(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 '].selecte dIndex=0;
objForm.elements['bldLabel '].selecte dIndex = 0;
objForm.submit();
}
function submitRegion(){
var objForm = document.forms[0];
objForm.elements['bldlabel '].selecte dIndex = 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;<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> < font face="Century Gothic" size="2" color="#008080"><%response .write request.form("cmpsub")%>
</font>
<font color="#008080">
<br />
</font> < font face="Century Gothic" size="2">Selected Codeline
</font> < font face="Century Gothic" size="2" color="#008080"><%response .write request.form("codeline")%>
</font>
</p>
<p align="center">   ; <fo nt face="Century Gothic" size="2"><font color="#808080">Please Select
</font><b>Build Label(s) </b></font>
</p>
<p align="center">   ; <%c all 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>
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")=
Session("UserName") = request.form("MName")
end if
%>
<html>
<head>
<meta http-equiv="Content-Langua
<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)=
{
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=PY1SPRODDEV
if not IsObject("ojbConnection") then
set objConnection=Server.Creat
objConnection.ConnectionTi
objConnection.CommandTimeo
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(
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></
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(
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,
if objRS.eof then
Response.Write("<option>No
else
'Response.Write("<option>S
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>Se
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(
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('_
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"),"_
tmp = Split(objRS("BldLabel"),"_
%>
<tr><td><font size="2" face="Century Gothic" color="#008080"><%=tmp%></
<%
end if
%>
<tr><td><input type=checkbox name=<%=objRS("BldLabel")%
<td><%=objRS("BldLabel")%>
</tr>
<%
objRS.MoveNext
loop
end if%>
</table>
</div>
<%
objRS.Close
set objRS=Nothing
else
'Response.Write("<p>Select
end if
end sub
%>
<SCRIPT LANGUAGE=javascript>
<!--
function submitCountry(){
var objForm = document.forms[0];
objForm.elements['codeline
objForm.elements['bldLabel
objForm.submit();
}
function submitRegion(){
var objForm = document.forms[0];
objForm.elements['bldlabel
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"> &
<img border="0" src="multilogo.jpg" width="436" height="115" /></p><p align="center">
<font face="Century Gothic" size="2">Selected Sub_System
</font> <
</font>
<font color="#008080">
<br />
</font> <
</font> <
</font>
</p>
<p align="center">  
</font><b>Build Label(s) </b></font>
</p>
<p align="center">  
</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>
ASKER
as is ?
or do I replace IformItem with my variable "bldLabel"
or do I replace IformItem with my variable "bldLabel"
ASKER
Okay that show the values correctly
ASKER
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.
<%= 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 ) %>
I did this
<%
dim iFormItem
For strBuild = 1 to Request.Form.Count %>
<%= Request.Form.Key(strBuild)
<% 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
ASKER
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
name=bldlabel and everything is working.
thanks
tmurray22
<%
dim iFormItem
For iFormItem = 1 to Request.Form.Count %>
<%= Request.Form.Key(iFormItem
<% Next %>