Reputation: 1
I have seen several posts on this and am still struggling to find a solution that works for me. I several check boxes that I need to loop through on a save. Here is what i have right now. It's an ASP page that is looping through record sets and writing out a lot of check boxes.
I've tried to use the hidden field to pass both "off" and "on" when the box is checked however its coming across on the server side as
off on
do while not rsHR.eof
idPOS = rsHR.fields("emplid")
idID = "ID" & idPOS
response.write("<TR>")
response.write("<TD nowrap align=left> " & rsHR.fields("EMPLID") & "</TD>")
response.write("<TD nowrap align=left> " & rsHR.fields("emp_name") & "</TD>")
response.write("<TD nowrap align=left> " & rsHR.fields("EMP_FLOOR") & "</TD>")
response.write("<TD nowrap align=left> " & rsHR.fields("RTO_GROUP") & "</TD>")
response.write("<TD>")
Response.Write("<INPUT type=hidden size=10 " & DisabledProperty & " id=WEEK1 name=" & idPOS & " value='off'><INPUT type=checkbox size=10 " & DisabledProperty & " id=WEEK1 name=" & idPOS & " defaultValue=" & tmp & " value=" & tmp & " onchange=week1(" & idID & ")>")
response.write("</TD>")
response.write("<TD>")
Response.Write("<INPUT type=hidden size=10 " & DisabledProperty & " id=WEEK2 name=" & idPOS & " value='off'><INPUT type=checkbox size=10 " & DisabledProperty & " id=WEEK2 name=" & idPOS & " defaultValue=" & tmp & " value=" & tmp & " onchange=week2(" & idID & ")>")
response.write("</TD>")
response.write("<TD>")
Response.Write("<INPUT type=hidden size=10 " & DisabledProperty & " id=WEEK3 name=" & idPOS & " value='off'><INPUT type=checkbox size=10 " & DisabledProperty & " id=WEEK3 name=" & idPOS & " defaultValue=" & tmp & " value=" & tmp & " onchange=week3(" & idID & ")>")
response.write("</TD>")
I was trying to handle setting the value in javascript with the onchange events but i can't get it to pass the values to my save.
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
var idxWEEK1 = 1;
var idxWEEK2 = 2;
var idxWEEK3 = 3;
var idxCHG = 14;
var idxEID = 15;
var btnSubmitPEX = document.formPEX.submitPEX;
var bsubmitingPEXform = 0
function week1(cntl) {
var x = document.getElementById("WEEK1").checked;
document.getElementById("demo").innerHTML = x;
cntl[idxCHG].value = "DIRTY";
btnSubmitPEX.disabled = false;
}
Any help or ideas is greatly appreciated!
Upvotes: 0
Views: 101
Reputation: 4663
The hidden fields aren't linked to the checkboxes, their values will be submitted whether the checkboxes are checked or not.
Consider this form
<form method="post">
<input type="hidden" name="myfield" value="off">
<input type="checkbox" name="myfield" value="on">
<input type="submit" value="Submit">
</form>
The hidden and checkbox fields have the same name - myfield - so Request.Form("myfield")
will have a value of "off" if the box is not checked or "off,on" if it is. If two or more values are received for the same form variable then VBScript will concatenate them with commas.
I'm not entirely sure what you're trying to achieve but here's a bit of server side code which might give you some ideas.
Dim MyVariable, checkedstatus
If Request.Form("myfield") = "on" then
MyVariable = "on"
checkedstatus = "checked"
Else
MyVariable = "off"
checkedstatus = ""
End If
Response.Write "<form method=""post"">" & vbcrlf
Response.Write " <input "& checkedstatus &" type=""checkbox"" name=""myfield"" value=""on"">" & vbcrlf
Response.Write " <input type=""submit"" value=""Submit"">" & vbcrlf
Response.Write "</form><br>" & vbcrlf
Response.Write MyVariable
Upvotes: 1