Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 18th, 2006, 10:54 AM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default checkbox update

Hi,
I have a form that has some checkboxes named "interests" like this:
<input type=checkbox name=interests value="sport">
<input type=checkbox name=interests value="Internet">
<input type=checkbox name=interests value="Books">

I add them to a field called "interests" in the database
and as you know they will be added with a comma separated(if user checks all thr boxes)like this sports,books,internet

Now I have a form that gets the values of all fields from the db
I get the values of all fields but how Can I update the interest field
if there was just one value I used this code:
<input type=checkbox name=interests value="<%=rs("interests")%>">
But now I have more than 1 checkbox
I need the code please!
 
Old April 18th, 2006, 06:39 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Pleaae dont cross post:
http://p2p.wrox.com/topic.asp?TOPIC_ID=43070

you need to split the commer delimited string on the commer (create array) find how many elements, then based on this number create a loop inserting each record.

     dim ids,numOfIds,count
     count = 0

     Function splitOnComer(stringVar)
        if isNull(stringVar) then
           'do nothing
        else
           ids = Split(stringVar, ",", -1, 0)
           numOfIds = (UBound(ids) +1)
        end if
     End function

     splitOnComer(request.form("gId"))
     do until count = numOfIds
        sql = "INSERT INTO userGroups(gid)VALUES(" & trim(ids(count)) & ");"
        conn.execute(sql)
        count = (count + 1)
     loop



Wind is your friend
Matt
 
Old April 19th, 2006, 02:07 AM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No,You did not get it.
I want to check which checkboxes have been checked like this
<input type=checkbox name=interests value="sports" <%if rs("interests")="sports" then response.write "checked"%>>
<input type=checkbox name=interests value="books" <%if rs("books")="sports" then response.write "checked"%>>
I agree I should split the string but what to do next

 
Old April 19th, 2006, 02:51 AM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

interesting reply, you asked:

;;;I get the values of all fields but how Can I update the interest field
That is exactly waht the code I gave you does

;;;I get the values of all fields but how Can I update the interest field
That is exactly what the code I gave you does

Dont you need to insert these chosen values before you check if they have been checked?

Others:
Did I 'not get it' or am I going a bit nuts


Wind is your friend
Matt
 
Old April 19th, 2006, 08:30 AM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for confusion
Now If I want to insert the actual text of checkbox instead of id what should I do?
thanks a lot

 
Old April 19th, 2006, 07:02 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

;;Sorry for confusion
I would have said sorry for being a bit abrupt. If you want assistance from forums you should choose your words more carefully. Im not confused. you asked a question and I gave you an answer. What are you confused about?

;;Now If I want to insert the actual text of checkbox instead of id what should I do?
Clearly you have not run the code. I have called variables 'ids' and 'numOfIds' these values can be any type of data and the 'splitOnComer' function will take strings and integers. FYI: a comer delimited string is a string. It does not matter if it is a string of numbers or integers. However if one of your strings have a commer you have a problem. this also illustrated to me you have not normalized your tables (look up normalization) you should be inserting an integer which represents a string value

The only thing in the code I posted that would change wiould be the sql (inserting into a varChar filed instead of a int field. So change:

sql = "INSERT INTO userGroups(gid)VALUES(" & trim(ids(count)) & ");"
To:
sql = "INSERT INTO tbleName(YourFieldName)VALUES('" & trim(ids(count)) & "');"


Wind is your friend
Matt
 
Old April 23rd, 2006, 02:00 PM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi mat41 the code worked like a dream
Only one problem (on my part)

ProdId gets split but now i need to do the exact same thing for qty, which will insert into the same table
Could you help me out please
Many Thanks

ProdID = Request.QueryString("productid")
qty = Request.QueryString("qty")


     Function splitOnComer(ProdId)
        if isNull(ProdId) then
           'do nothing
        else
           ids = Split(ProdId, ",", -1, 0)
           numOfIds = (UBound(ids) +1)
        end if
     End function

     splitOnComer(Request.QueryString("productid"))
      do until count = numOfIds
 sql = "INSERT INTO test(productID)VALUES('" & trim(ids(count)) & "');"
      conn.execute(sql)
        count = (count + 1)
     loop


 
Old April 23rd, 2006, 06:45 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

mrKhagram. You are welcome. I use, and have used this process for a, well god only knows how long.... not sure what keyvanjan's smoking - I had a look at his profile to see if he is from a non-english speaking country, thinking perhaps the cofusion of the english language was his issue. A skinny profile to say the least...

;;;which will insert into the same table Could you help me out please
To avoid running the risk of a mis-understanding may I ask; the page that is recieving the values from your form is:
1..trouble free?
2..expecting two commer delimited strings which need to be split and inserted into the same table in similar fasion to the code I have posted above?
3..I assume there could be any number of values in each string?
4..What are the two field names?
   a..What are the data types?
   b..are nulls allowed - if not, is a default values being auto inserted (done within EM [assuming you are using SQL Server])
FYI: my angle on the 4,4a,4b question is - do these fields need to be addressed in a scenario like:
we have five values in one string and 3 in the other (two nested loops doing the insert) can I simply not address the field where we only have three values remembering the loop needs to be executed five times for our bigger array?





Wind is your friend
Matt
 
Old April 24th, 2006, 07:24 AM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To avoid running the risk of a mis-understanding may I ask; the page that is recieving the values from your form is:
1..trouble free?

Yes the page receiving works fine, here is a snippet:

<input type="checkbox" name="productid" value="<%=rs("product_code")%>">
          <td width="100"><%=(rs.Fields("product_name").Value)%> </td>
                   <input type="text" name="qty" size="5"></p>


Which is looped so prints out all Products, filename "start_order.asp"

2..expecting two commer delimited strings which need to be split and inserted into the same table in similar fasion to the code I have posted above?

Yes. So ProductCode and Qty (both Number types in access) will be commer delimited integers, and into a table actually not test but order_picking which has also InvoiceNumber (will pass through hidden variable) . This will also have a Date() field. So 4 fields in order_picking.

3..I assume there could be any number of values in each string?
Yes, for as many products they have ordered

4..What are the two field names?
product_id and quantity, of type number

   b..are nulls allowed - if not, is a default values being auto inserted (done within EM [assuming you are using SQL Server])
FYI: my angle on the 4,4a,4b question is - do these fields need to be addressed in a scenario like:
we have five values in one string and 3 in the other (two nested loops doing the insert) can I simply not address the field where we only have three values remembering the loop needs to be executed five times for our bigger array?

No its nothing like that, although there should be no nulls (if there is then the user hasnt checked or typed in qty. And im not using SQL Server

 
Old April 24th, 2006, 10:10 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Im glad I asked the questions, you say:

;;;No its nothing like that, although there should be no nulls
Please re-read 4b and the FYI bit again. Is there anuthing there you so not understand? Why do I ask:
If there is to be no nulls and there is no default values being inserted (set up in design view of Access - not in the page code) what is the code to insert when one string has more values than the other?

FYI: I do not understand what you are meaning when you say:
;;;No its nothing like that

Additionaly when I say:
(done within EM [assuming you are using SQL Server])
Replace with:
(done in design view of Access [assuming you are using Access])


Wind is your friend
Matt




Similar Threads
Thread Thread Starter Forum Replies Last Post
update database with checkbox mike7510uk ASP.NET 2.0 Basics 1 December 12th, 2006 07:10 AM
update records in the database by checkbox Sakina Classic ASP Basics 2 September 9th, 2006 11:38 PM
checkbox update keyvanjan Classic ASP Professional 1 April 18th, 2006 06:41 PM
Gridview Checkbox Update not updating using Access AUhawk ASP.NET 2.0 Basics 0 October 27th, 2005 01:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.