Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checked or unchecked, that is the question.

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
What I want to do is update records depending on the if the record was checked or unchecked. I have tried a few ways of doing this but I can't seem to get them to work. On this way below it only returns 1 checked box that is checked, if anymore are checked, it just returns all user ids..


Is there a better way of doing this, or do you see why this way isnt working?
Code:
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;check.asp&quot;>
  <input type=&quot;checkbox&quot; name=&quot;payed&quot; value=&quot;1&quot;>
  <input type=&quot;hidden&quot; name=&quot;alluserids&quot; value=&quot;1&quot;>
  <input type=&quot;checkbox&quot; name=&quot;payed&quot; value=&quot;2&quot;>
  <input type=&quot;hidden&quot; name=&quot;alluserids&quot; value=&quot;2&quot;>
  <input type=&quot;checkbox&quot; name=&quot;payed&quot; value=&quot;3&quot;>
  <input type=&quot;hidden&quot; name=&quot;alluserids&quot; value=&quot;3&quot;>
  <input type=&quot;checkbox&quot; name=&quot;payed&quot; value=&quot;4&quot;>
  <input type=&quot;hidden&quot; name=&quot;alluserids&quot; value=&quot;4&quot;>
  <input type=&quot;checkbox&quot; name=&quot;payed&quot; value=&quot;5&quot;>
  <input type=&quot;hidden&quot; name=&quot;alluserids&quot; value=&quot;5&quot;>
  <input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
  <input type=&quot;hidden&quot; name=&quot;save&quot; value=&quot;true&quot;>
</form>

<%
If Request.Form(&quot;save&quot;) = &quot;true&quot; then

Dim frmAlluserids, frmPayed
Dim tmpFrmPayed, tmpAll

Dim IDsPayed, IDsNotPayed
Dim TmpPayedID
Dim TmpNotPayedID


frmAll = Request.Form(&quot;alluserids&quot;)
frmPayed = Request.Form(&quot;payed&quot;)

tmpAll  = Replace(frmAll, &quot;, &quot;, &quot;,&quot;)
tmpFrmPayed = Replace(frmPayed, &quot;, &quot;, &quot;,&quot;)

frmAll = Split(tmpAll,&quot;,&quot;)

For each check in frmAll

If Instr(check,tmpFrmPayed) > 0 then
	IDsPayed = IDsPayed & space(1) & check
End If

If Instr(check,tmpFrmPayed) < 1 then
	IDsNotPayed = IDsNotPayed & space(1) & check
End If

Next

TmpPayedID = Trim(IDsPayed)
TmpNotPayedID = Trim(IDsNotPayed)

IDsPayed = Replace(TmpPayedID, &quot; &quot;, &quot;, &quot;)
IDsNotPayed = Replace(TmpNotPayedID, &quot; &quot;, &quot;, &quot;)



Response.Write IDsPayed & &quot;<br><br>IDs not checked&quot; & IDsNotPayed
End if

%>
www.vzio.com
ASP WEB DEVELOPMENT



 
I just tried your form, seemed to pass things just fine.
Here's my test code (i called it payed.asp):
Code:
<%
Option Explicit

Response.Write &quot;p:&quot; & Request.QueryString(&quot;payed&quot;) & &quot;<br>&quot;
Response.Write &quot;A:&quot; & Request.QueryString(&quot;alluserids&quot;) & &quot;<br>&quot;
%>
<!doctype html public &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>
<title> New Document </title>
</head>
<body>
<form name=&quot;form1&quot; method=&quot;get&quot; action=&quot;payed.asp&quot;>
  <input type=&quot;checkbox&quot; name=&quot;payed&quot; value=&quot;1&quot;>
  <input type=&quot;hidden&quot; name=&quot;alluserids&quot; value=&quot;1&quot;>
  <input type=&quot;checkbox&quot; name=&quot;payed&quot; value=&quot;2&quot;>
  <input type=&quot;hidden&quot; name=&quot;alluserids&quot; value=&quot;2&quot;>
  <input type=&quot;checkbox&quot; name=&quot;payed&quot; value=&quot;3&quot;>
  <input type=&quot;hidden&quot; name=&quot;alluserids&quot; value=&quot;3&quot;>
  <input type=&quot;checkbox&quot; name=&quot;payed&quot; value=&quot;4&quot;>
  <input type=&quot;hidden&quot; name=&quot;alluserids&quot; value=&quot;4&quot;>
  <input type=&quot;checkbox&quot; name=&quot;payed&quot; value=&quot;5&quot;>
  <input type=&quot;hidden&quot; name=&quot;alluserids&quot; value=&quot;5&quot;>
  <input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
  <input type=&quot;hidden&quot; name=&quot;save&quot; value=&quot;true&quot;>
</form>
</body>
</html>

I think your InStr's may be backwards, the correct format is:
InStr(string,char)
or
InStr(start,string,char) 'may not work in ASP, not sure

Switch them and see if your results differ.
-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
After playing a bit with your code, I can't see how you are getting any results. With the Instrs reversed above, nothing matches and I get a blank string for not payed every singel time. Try this instead of the code above:
Code:
If Request.Form(&quot;save&quot;) = &quot;true&quot; then

Dim payList
Dim fullArray
Dim notPayedList, check  'check is probably already dim'd for you

payList = Request.Form(&quot;payed&quot;)

fullArray = Split(Request.Form(&quot;alluserids&quot;),&quot;, &quot;)

For each check in fullArray
	If InStr(payList,check) > 0 Then
		notPayedList = notPayedList & &quot; &quot; & check
	End If
Next

Response.Write &quot;Not Payed: &quot; & notPayedList

End If

-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top