www.webdeveloper.com
Results 1 to 2 of 2

Thread: How would u do this

  1. #1
    Join Date
    Jun 2004
    Location
    Kansas City, MO
    Posts
    1,607

    How would u do this

    I have done this several ways and i guess im just curious how others tackle this. I am getting ready to do this and then i was like " i wonder if there is a better way". So here we go.

    I am reading values from the DB and for each record i will create a textbox.
    As i loop i will have a counter. It will look like this

    Code:
    <%
    i = 0 
    
    Do While Not objRS.EOF
    i = i + 1 
    %>
           <tr>
                <td><input type="text" name="txtHrs_<%=i%>"></td>
           </tr>
    <%
         objRS.MoveNext
    Loop
    %>
    For the sake of an example, lets say i loop 3 times. So i have
    txtHrs_1
    txtHrs_2
    txtHrs_3 For the names of my textboxes.

    Now when i submit the form and write back to the DB, im going to do
    something like this.
    Code:
    For i = 1 to 3
          hrs = Request.form("txthrs_" & i) 
    
          'do my db stuff and add this value
    Next
    Now this example is for a set number of records, this wont be the case w/ the application.
    Also if some of the syntax is off thats ok, this was just an example, i did not include all the code, such as for i = 1 to 3, well yes i would not hard code the 3, that would depend on how many records were looped, etc.

    Any way i just wanted to see what other options i have available as this is the way i usually do it, but i thought about using the Forms collection, but have never done that and im not sure if the Forms collection will just return my text box or if its going to return the buttons, radio, check, text, tetxtarea, etc.

    Or it might just be that the way i do it is perfectly fine.

    Thats it.

  2. #2
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    The form collection will return everything, regardless of its control type. Although, it will not return radio boxed and check boxes if they have not been checked. This is a browser thing, though, as the client will not pass data like this to the server unless it has to. You are actually using the forms collection everytime you do something like Request.Fom("fff").

    If you were using the right cursortype, you could use a for loop here and get rid of the do...while
    Code:
    For i = 0 To objRS.RecordCount
    %>
           <tr>
                <td><input type="text" name="txtHrs_<%=i%>"></td>
           </tr>
    <%
         objRS.MoveNext
    Next
    Regards.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles