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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checkbox help

Status
Not open for further replies.

thompom

Technical User
Dec 4, 2006
395
0
0
GB
Hi,

Have multiple checkboxes on my form that I need to loop through and see which ones are 'checked' - then if the checked ones match an ID in a recordset I want to write 1 to a field.

Have requested the 'x_pxselect' values and written them out so I know that part works ok, but am having issue writing to the RS.

problem is only one record ever gets a 1 in select field - interestingly if I tick both boxes the 'selected' records get switched

hope im makeing sense - long day ;-)

html
Code:
<input name='x_pxselect' type="checkbox" value="20" checked/>
<input name='x_pxselect' type="checkbox" value="19"/>

asp
Code:
eventstocklinkSQL = "SELECT * FROM eventstocklink "_
& "WHERE eventstocklink.eventid = '" & action.eventid.SessionValue & "' "_
& "AND statusid = 5"

'checked sql and outputs two cars
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = EW_CURSORLOCATION
rs.Open eventstocklinkSQL, conn, 1, 2
	
'loop through rs to get id
Do while not rs.eof
x_eventstocklinkid = rs("eventstocklinkid")

'loop through checkbox to get id
For Each x_pxselect In Request.Form("x_pxselect")
if x_pxselect = "" then x_pxselect = 0
'response.Write (x_pxselect) & " " & x_eventstocklinkid & " <br>"

'match id of rs to key of checkbox
if CINT(x_pxselect) = x_eventstocklinkid then
'write value
	rs("select") = 1
	end if
Next	

'update rs
	rs.update	
	rs.movenext
	loop
'close rs		
	rs.close
	set rs = nothing
 
Deduced from the sql, I reckon x_eventstocklinkid is a string of numeric in it. Hence, either:
>if CINT(x_pxselect) = x_eventstocklinkid then
[tt]if CINT(x_pxselect) = [red]CINT([/red]x_eventstocklinkid[red])[/red] then[/tt]
or
[tt][red]'[/red]if x_pxselect = "" then x_pxselect = 0 'you don't really need this
if x_pxselect = x_eventstocklinkid then[/tt]
 
hi tsuji - did have that extra CINT in their at one point
thanks for spotting it, put it in and didnt help

however - think the issue was i needed an EXIT FOR after writing the value as 1

the code below works fine
Code:
pxcheck = 0
Do while not rs.eof
x_eventstocklinkid = rs("eventstocklinkid")
x_eventstocklinkid = trim(x_eventstocklinkid)

For Each x_pxselect In Request.Form("x_pxselect")
pxcheck = 1
x_pxselect = trim(x_pxselect)
if CINT(x_pxselect) = CINT(x_eventstocklinkid) then
	rs("select") = 1
	EXIT FOR
	else
	rs("select") = 0
	end if
Next	

if pxcheck = 0 then
rs("select") = 0
end if
rs.update	
rs.movenext
loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top