SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multi checkbox insert

    I have a form that is passing a number to check box values with the same name (productID) but different values (numerical values). It is also passing a warehouseID as a hidden field.

    I need to dump these values into an access table called wtbProductWarehouses with fields titled ProductID and WarehouseID. What is the code that I need to write to have it loop through all of the productID values and individually add each one to the db while also adding the warehouseID with it.

    Thanks so much!

    Jason

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is the value of each checkbox the ID of a warehouse? If not, then what is it?

    If you have for example:
    Code:
    <input type="checkbox" name="prod_0001" value="1001" />
    <input type="checkbox" name="prod_0001" value="1002" />
    <input type="checkbox" name="prod_0001" value="1003" />
    <input type="checkbox" name="prod_0002" value="1001" />
    <input type="checkbox" name="prod_0002" value="1004" />
    <input type="checkbox" name="prod_0002" value="1005" />
    then in your ASP to handle the form you can do:
    Code:
    For Each sItem In Request.Form
    
    	' look for product checkboxes
    	If InStr(1, sItem, "prdchk_") > 0 Then
    		' get the product id and warehouse id
    		sProdId = Split(sItem, "_")(1)
    		sWareId = Request.Form(sItem)
    		
    		' do something with prod id and ware id
    		sSQL = "INSERT INTO ProdWarehs (ProdId, WareId) VALUES(" & sProdId & "," & sWareId & ")"
    	
    	End If
    
    Next

  3. #3
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Tried to modify but it is still not working...What did I not get right?

    For Each sItem In Request.Form
    ' look for product checkboxes
    If InStr(1, sItem, "productID") > 0 Then
    ' get the product id and warehouse id
    sProdId = Split(sItem, "_")(1)
    sWareId = Request.Form(sItem)

    ' do something with prod id and ware id
    sSQL = "INSERT INTO wtbProductWarehouses (productID, warehouseID) VALUES(" & sProdId & "," & sWareId & ")"
    Conn.Execute sSQL
    End If
    Next


    I'm getting this error...
    Microsoft VBScript runtime error '800a0009'

    Subscript out of range: '[number: 1]'

    /admin/wtbAdmin/updatePW.asp, line 21

    Thanks

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That only works if you use underscores in the checkbox name attributes like I did - I bet you dont have those

    If your names are like
    productID00001
    productID00002

    replace
    sProdId = Split(sItem, "_")(1)
    with
    sProdId = Replace(sItem, "productId", "")


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •