|
I have a problem and was wondering if you could help.
I have a form that i am currently doing batch updates. The problem i have is -
If a user clicks a checkbox, i need a hidden object to receive 1, if they uncheck it, the the hidden object recieves 0. Here is what i have,
<script language="JavaScript" type="text/JavaScript">
function checked()
{
if (document.form1.RFr_Selected<%=(rs.Fields.Item("Entry_Id").Value)%>.checked == true)
document.form1.RFr_Printed<%=(rs.Fields.Item("Entry_Id").Value)%>.value = 1;
else
document.form1.RFr_Printed<%=(rs.Fields.Item("Entry_Id").Value)%>.value = 0;
}
</script>
This script works, but only for the first record (checkbox). How do I go about getting the rest of the checkboxes to work also?
Could anyone help? Thanks in advance!
|
|
|
First, this seems odd -- why not just use the checkbox value in your ASP? Why a matching hidden element for each checkbox? Just use the checkboxes. Give them all a value of "1", then they will return a "1" if they are checked and they wont exist if they are not checked--which you can equate to zero in your code.
But if you really want to do what you describe...Here is code to do what you requested. Instead of hard coding the "id" in the call to SetHiddenVal() like I did, you would dynamically insert that using your ASP code as you loop over the recordset (or whatever you are doing).
<script language="javascript">
function SetHiddenVal(id) {
cName = "cb" + id;
hName = "h" + id;
if (document.form1.elements[cName].checked) {
document.form1.elements[hName].value = 1;
} else {
document.form1.elements[hName].value = 0;
}
alert(document.form1.h1.value);
alert(document.form1.h2.value);
alert(document.form1.h3.value);
}
</script>
<form name="form1">
<input type=checkbox name="cb1" value="1" onclick="SetHiddenVal(1)">
<input type=checkbox name="cb2" value="1" onclick="SetHiddenVal(2)">
<input type=checkbox name="cb3" value="1" onclick="SetHiddenVal(3)">
<input type=hidden name="h1" value=0>
<input type=hidden name="h2" value=0>
<input type=hidden name="h3" value=0>
</form> |
|
|
|
|
|
|
Thanks for the reply.
How would I send a zero if it is not checked?
<Added>
Here is my code. Basically i am returning a recordset, then a user will click a check box under 1 of 4 columns. If they check the box, i will do a print routine(not shown here), but if they dont click a box nothing gets printed. The Issue:
If they do click one of many boxes, they update the table, the next time through,i update the hidden field in the database to 2. (This is so they will not print this again.) What would really work is if i could disable the checkbox, and send a 1 to the database.(But you cant if it is disabled)
Please advise.
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="/forum/Connections/Schedule_Tracker.html" -->
<%session("update_line")=Request.QueryString("update_line")%>
<%session("update_date")=Request.QueryString("update_Due_Date")%>
<%
Dim rs__vardue
rs__vardue = "1/1/2004"
If (Session("view_date") <> "") Then
rs__vardue = Session("view_date")
End If
%>
<%
Dim rs__MMColParam
rs__MMColParam = "0"
If (Session("view_line") <> "") Then
rs__MMColParam = Session("view_line")
End If
%>
<%
set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = MM_Schedule_Tracker_STRING
rs.Source = "SELECT * FROM Entry WHERE (Line_Id = " + Replace(rs__MMColParam, "'", "''") + ") and (Due_Date = #" + Replace(rs__vardue, "'", "''") + "#) ORDER BY Sequence_Order ASC"
rs.CursorType = 0
rs.CursorLocation = 2
rs.LockType = 3
rs.Open()
rs_numRows = 0
%>
<%
Dim Line_Desc__varL3
Line_Desc__varL3 = "0"
If (Session("view_line") <> "") Then
Line_Desc__varL3 = Session("view_line")
End If
%>
<%
Dim Line_Desc
Dim Line_Desc_numRows
Set Line_Desc = Server.CreateObject("ADODB.Recordset")
Line_Desc.ActiveConnection = MM_Schedule_Tracker_STRING
Line_Desc.Source = "SELECT * FROM Line WHERE Line_Id=" + Replace(Line_Desc__varL3, "'", "''") + ""
Line_Desc.CursorType = 0
Line_Desc.CursorLocation = 2
Line_Desc.LockType = 1
Line_Desc.Open()
Line_Desc_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
rs_numRows = rs_numRows + Repeat1__numRows
%>
<%
if request("selected") <> "" Then
rs.MoveFirst
while not rs.eof
Entry_Id=rs("Entry_Id")
'rs("RFr_Selected")=NotNull(Request("RFr_Selected" & Entry_Id))
rs("RFr_Selected")=DoCheck(Request("RFr_Selected" & Entry_Id))
rs("LFr_Selected")=DoCheck(Request("LFr_Selected" & Entry_Id))
rs("RRr_Selected")=DoCheck(Request("RRr_Selected" & Entry_Id))
rs("LRr_Selected")=DoCheck(Request("LRr_Selected" & Entry_Id))
rs("RFr_Printed")=Request("RFr_Selected" & Entry_Id)
rs("LFr_Printed")=Request("LFr_Selected" & Entry_Id)
rs("RRr_Printed")=Request("RRr_Selected" & Entry_Id)
rs("LRr_Printed")=Request("LRr_Selected" & Entry_Id)
rs("Lot_To_Print")=Request("Lot_To_Print" & Entry_Id)
rs("Num_To_Print")=Request("Num_To_Print" & Entry_Id)
rs.update
rs.Movenext
wend
response.redirect "/forum/excel.html"
end if
function DoCheck(fld)
if fld <> "" then
DoCheck=1
else
DoCheck=0
end if
end function
%>
<html>
<head>
<title>TS Trim Schedule Tracker</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function GP_popupConfirmMsg(msg) { //v1.0
document.MM_returnValue = confirm(msg);
}
//-->
</script>
<STYLE TYPE="text/css">
<!-- /* $WEFT -- Created by: Josh Barton (josh_barton@tstna.com) on 11/11/2003 -- */
@font-face {
font-family: BN-NoFear;
font-style: normal;
font-weight: normal;
src: url(BNNOFEA0.eot);
}
-->
</STYLE>
</head>
<body>
<table width="600" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="20%" rowspan="2"><a href="/forum/options.html"><img src="/forum/images/logo.gif" width="250" height="85" border="0"></a></td>
<td width="80%"><font size="5" face="BN-NoFear"><strong>Print Production
Labels</strong></font></td>
</tr>
<tr>
<td height="25"><font size="3" face="BN-NoFear">
<script language="Javascript">
var dayName = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
var monName = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
var now = new Date
document.write("Today is " + dayName[now.getDay()] + ", " + monName[now.getMonth()] + " " +[now.getDate()] + " .")
</script>
</font></td>
</tr>
</table>
<%= Session("view_date") %><%= Session("view_line") %><a href="/forum/options.html"> </a>
<% If Not rs.EOF Or Not rs.BOF Then %>
<form action="" method="post" name="form1">
<table width="675" border="0">
<tr>
<td colspan="10"><font size="2" face="Arial, Helvetica, sans-serif">Please
update all columns accordingly. </font></td>
<td width="50"><font size="2" face="Arial, Helvetica, sans-serif"> </font></td>
<td width="59"><font size="2" face="Arial, Helvetica, sans-serif"> </font></td>
<td width="192"><font size="2" face="Arial, Helvetica, sans-serif"> </font></td>
</tr>
<tr>
<td colspan="14"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Schedule
Number :</strong> <%=(rs.Fields.Item("Schedule_Number").Value)%> <strong>Location
: </strong><%=(rs.Fields.Item("Location").Value)%> <strong>Line
: </strong> <%=(Line_Desc.Fields.Item("Ext_Description").Value)%></font><font size="1" face="Arial, Helvetica, sans-serif">
<input name="Updated<%=(rs.Fields.Item("Entry_Id").Value)%>" type="hidden" id="Updated<%=(rs.Fields.Item("Entry_Id").Value)%>3" value="<%= Session("user") %>">
</font></td>
</tr>
<tr>
<td colspan="12"><font size="2" face="Arial, Helvetica, sans-serif"> </font><font size="2" face="Arial, Helvetica, sans-serif"> </font><font size="2" face="Arial, Helvetica, sans-serif"> </font><font size="1" face="Arial, Helvetica, sans-serif"> </font></td>
</tr>
<tr>
<td width="93"><strong><font size="2" face="Arial, Helvetica, sans-serif">Lot Number</font></strong></td>
<td width="56"><strong><font size="2" face="Arial, Helvetica, sans-serif">RFr</font></strong></td>
<td width="63"><strong><font size="2" face="Arial, Helvetica, sans-serif">LFr</font></strong></td>
<td><strong><font size="2" face="Arial, Helvetica, sans-serif">RRr</font></strong></td>
<td><strong><font size="2" face="Arial, Helvetica, sans-serif">LRr</font></strong></td>
<td colspan="9"><strong><font size="2" face="Arial, Helvetica, sans-serif">Qty</font></strong></td>
</tr>
<%
Dim RecordCounter
RecordCounter = 0
%>
<%
While ((Repeat1__numRows <> 0) AND (NOT rs.EOF))
%>
<tr
<%
RecordCounter = RecordCounter + 1
If RecordCounter Mod 2 = 1 Then
Response.Write "bgcolor=silver"
End If
%>
>
<td><font size="1" face="Arial, Helvetica, sans-serif"><%=(rs.Fields.Item("Lot_Number").Value)%>
<input name="Lot_Number<%=(rs.Fields.Item("Entry_Id").Value)%>" type="hidden" id="Lot_Number<%=(rs.Fields.Item("Entry_Id").Value)%>" value="<%=(rs.Fields.Item("Lot_Number").Value)%>">
</font></td>
<td><input name="RFr_Selected<%=(rs.Fields.Item("Entry_Id").Value)%>" type="checkbox" id="RFr_Selected<%=(rs.Fields.Item("Entry_Id").Value)%>" onClick="document.form1.Num_To_Print<%=(rs.Fields.Item("Entry_Id").Value)%>.value=document.form1.Qty<%=(rs.Fields.Item("Entry_Id").Value)%>.value;document.form1.Lot_To_Print<%=(rs.Fields.Item("Entry_Id").Value)%>.value=document.form1.Lot_Number<%=(rs.Fields.Item("Entry_Id").Value)%>.value" value="1"<%If (CStr((rs.Fields.Item("RFr_Selected").Value)) = CStr("True")) Then Response.Write("checked") : Response.Write("")%>>
<input name="RFr_Printed<%=(rs.Fields.Item("Entry_Id").Value)%>" type="hidden" id="RFr_Printed<%=(rs.Fields.Item("Entry_Id").Value)%>" value="<%=(rs.Fields.Item("RFr_Printed").Value)%>">
</td><td><input onClick="document.form1.LFr_Printed<%=(rs.Fields.Item("Entry_Id").Value)%>.value=document.form1.LFr_Selected<%=(rs.Fields.Item("Entry_Id").Value)%>.value;document.form1.Num_To_Print<%=(rs.Fields.Item("Entry_Id").Value)%>.value=document.form1.Qty<%=(rs.Fields.Item("Entry_Id").Value)%>.value;document.form1.Lot_To_Print<%=(rs.Fields.Item("Entry_Id").Value)%>.value=document.form1.Lot_Number<%=(rs.Fields.Item("Entry_Id").Value)%>.value"<%If (CStr((rs.Fields.Item("LFr_Selected").Value)) = CStr("True")) Then Response.Write("checked") : Response.Write("")%> name="LFr_Selected<%=(rs.Fields.Item("Entry_Id").Value)%>" type="checkbox" id="LFr_Selected<%=(rs.Fields.Item("Entry_Id").Value)%>" value="1">
<input name="LFr_Printed<%=(rs.Fields.Item("Entry_Id").Value)%>" type="hidden" id="LFr_Printed<%=(rs.Fields.Item("Entry_Id").Value)%>" value="<%=(rs.Fields.Item("LFr_Printed").Value)%>">
</td>
<td width="70"><input onClick="document.form1.RRr_Printed<%=(rs.Fields.Item("Entry_Id").Value)%>.value=document.form1.RRr_Selected<%=(rs.Fields.Item("Entry_Id").Value)%>.value"<%If (CStr((rs.Fields.Item("RRr_Selected").Value)) = CStr("True")) Then Response.Write("checked") : Response.Write("")%> name="RRr_Selected<%=(rs.Fields.Item("Entry_Id").Value)%>" type="checkbox" id="RRr_Selected<%=(rs.Fields.Item("Entry_Id").Value)%>" value="1">
<input name="RRr_Printed<%=(rs.Fields.Item("Entry_Id").Value)%>" type="hidden" id="RRr_Printed<%=(rs.Fields.Item("Entry_Id").Value)%>" value="<%=(rs.Fields.Item("RRr_Printed").Value)%>">
</td>
<td width="63"><input onClick="document.form1.LRr_Printed<%=(rs.Fields.Item("Entry_Id").Value)%>.value=document.form1.LRr_Selected<%=(rs.Fields.Item("Entry_Id").Value)%>.value"<%If (CStr((rs.Fields.Item("LRr_Selected").Value)) = CStr("True")) Then Response.Write("checked") : Response.Write("")%> name="LRr_Selected<%=(rs.Fields.Item("Entry_Id").Value)%>" type="checkbox" id="LRr_Selected<%=(rs.Fields.Item("Entry_Id").Value)%>" value="1">
<input name="LRr_Printed<%=(rs.Fields.Item("Entry_Id").Value)%>" type="hidden" id="LRr_Printed<%=(rs.Fields.Item("Entry_Id").Value)%>" value="<%=(rs.Fields.Item("LRr_Printed").Value)%>">
</td>
<td colspan="9"><font size="1" face="Arial, Helvetica, sans-serif"> <input name="Lot_To_Print<%=(rs.Fields.Item("Entry_Id").Value)%>" type="hidden" id="Lot_To_Print<%=(rs.Fields.Item("Entry_Id").Value)%>">
<input name="Qty<%=(rs.Fields.Item("Entry_Id").Value)%>" type="text" id="Qty<%=(rs.Fields.Item("Entry_Id").Value)%>" value="<%=(rs.Fields.Item("Qty").Value)%>">
<input name="Num_To_Print<%=(rs.Fields.Item("Entry_Id").Value)%>" type="text" id="Num_To_Print<%=(rs.Fields.Item("Entry_Id").Value)%>" value="0">
</font></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rs.MoveNext()
Wend
%>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td colspan="3"> </td>
<td width="31"><font size="1" face="Arial, Helvetica, sans-serif">
</font> </td>
<td width="31"> </td>
<td width="31"> </td>
<td width="31"> </td>
<td> </td>
<td>
<div align="center"> </div>
</td>
<td> </td>
</tr>
<tr>
<td colspan="3"><input name="Submit" type="submit" onClick="GP_popupConfirmMsg('Are you sure you want to continue?');return document.MM_returnValue" value="Update Schedule">
</td>
<td colspan="3"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<input name="selected" type="hidden" id="selected" value="1">
</form>
<% End If ' end Not rs.EOF Or NOT rs.BOF %>
<hr>
<font color="#000000" size="2" face="Arial, Helvetica, sans-serif"><em>Copyright ©2003
TS Trim Industries, Inc.</em></font></body>
</html>
<%
rs.Close()
%>
<%
Line_Desc.Close()
Set Line_Desc = Nothing
%>
|
|
|
I think I understand what you are trying to do. I'm going to propose this solution. Forget the hidden form elements. Also, instead of naming your checkboxes using the ID, give them all the same name. Instead of setting the value of each checkbox to "1", set it to the ID from your recordset. Your HTML will end up looking something like this:
<input type=checkbox name="printColumns" value=1> Column 1
<br><input type=checkbox name="printColumns" value=2> Column 2
<br><input type=checkbox name="printColumns" value=3> Column 3
<br><input type=checkbox name="printColumns" value=4> Column 4 |
|
When this form is submitted, your server-side code will receive a single form variable named "printColumns" that will contain a comma-seperated list of the ID's to print. Here is how I typically parse this value:
printColumns = "," & Replace(Request.Form("printColumns"),", ",",")
for idx = 1 to 4
if InStr(1,printColumns,"," & idx) then
'Here you could set some variable to 1.
Response.Write("Column " & idx & " will be printed.<br>")
else
'Here you could set some variable to 0.
Response.Write("Column " & idx & " will NOT be printed.<br>")
end if
next |
| Instead of idx = 1 to 4, you'd be looping through a recordset perhaps--or however you need to control the loop iterations.
Here is a fully-working ASP page to show this in action. Copy & Paste this as a new ASP page, then run it on your webserver. (Remember, you can't just double click an ASP file from your filesystem--you have to browse to the page.)<%
if Request.Form.Count > 0 then
printColumns = "," & Replace(Request.Form("printColumns"),", ",",")
for idx = 1 to 4
if InStr(1,printColumns,"," & idx) then
'Here you could set some variable to 1.
Response.Write("Column " & idx & " will be printed.<br>")
else
'Here you could set some variable to 0.
Response.Write("Column " & idx & " will NOT be printed.<br>")
end if
next
else
%>
<script language=javascript>
</script>
<body>
<form name="myForm" method="POST">
<input type=checkbox name="printColumns" value=1> Column 1
<br><input type=checkbox name="printColumns" value=2> Column 2
<br><input type=checkbox name="printColumns" value=3> Column 3
<br><input type=checkbox name="printColumns" value=4> Column 4
<p>
<input type=submit>
</form>
</body>
<%
end if
%> |
|
|
|
|
|
|
Thanks Troy for your quick response!
|
|
|
|
|
|
|
|