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

Check Boxes

Status
Not open for further replies.

prog247

Programmer
Mar 16, 2001
17
0
0
US
Hey, I have a page with the couple of check boxes, they have the same name and the diferent values. When user send the form with the checked checkboxes I catch the name of the checkbox on the next page and trying to do an insert into db. The problem is they have the same name and the value are pasing like this 1, 2, 3, 4, 5 and it's all in one variable. I can't do an insert I mean I can write the function and delete the commad but it is to coplicated. So how can i do that or maybe someone has a complete function. Than you.
 
Have the following code in the ACTION page. This peice of code UPDATEs the table. You may modify this for INSERT functionality.. It should be fairly simple.. The following code is a Guideline Only.

Code:
If Request.Form("chk").Count > 0 THEN 
 for i = 1 to Request.Form("chk").Count
  If  Request.Form(&quot;chk&quot;).Item(i) <> &quot;&quot; THEN 		 
    sList = sList & CSTR(Request.Form(&quot;chk&quot;).Item(i)) & &quot; &quot;
  END IF
 Next 	
	
	
	sList = Replace(sList,&quot; &quot;, &quot;,&quot;,1,Len(sList),1)
	sList = Left(sList, Len(sList)-1)	
	sList=&quot;(&quot; & sList & &quot;)&quot;	

	strSQL = &quot;UPDATE whatever_table SET TIMESTAMP=('&quot; & CDATE(Now()) & &quot;') &quot;
	strSQL = strSQL & &quot;, EMAIL='&quot; & Request.Cookies(&quot;EMAIL&quot;)   & &quot;' WHERE &quot;
	strSQL = strSQL & &quot;  EMP_ID IN (SELECT EMP_ID FROM EMP_MASTER WHERE ID IN &quot; & sList  & &quot;)&quot;
	objCon.Execute strSQL
	
	If Err.number <> 0 THEN 
		Response.Write Err.Description
	ELSE		
	'Success code here..
		SET  objRec = NOTHING
		objCon.Close
		SET objCOn = NOTHING
	END IF
ELSE
	Response.Write &quot;<SPAN STYLE='background-color=ivory' width='1000'>None of the checkboxes were selected..</SPAN>&quot;         
END IF
Thank you...
RR

 
Even easier, take the comma delimited string and turn it into an array (almost the same as what despratecoder does) using the VBScript built in function Split(), then manuipulate it.

(Guide line only)


strList = Request.Form.item(&quot;chk&quot;).value
aryList = Split(strList,&quot;,&quot;)

For i=0 to Ubound(aryList,2)

'SQL
strSQL = &quot;INSERT INTO myTable SET item_one = &quot; & aryList(i)
strSQL = &quot; WHERE item_two = (SELECT top 1 item_one FROM&quot;
strSQL = &quot; aDifferentTable WHERE item_two = &quot; & aryList(i)

'Insert
Call objCommand.execute(strSQL)

Next




 
This may sound simplistic but why don't you just change the names on the checkboxes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top