Results 1 to 4 of 4

Thread: [RESOLVED] - load the html text controls dynamically question

  1. #1

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Resolved [RESOLVED] - load the html text controls dynamically question

    if i load the html text controls dynamically how can i reference each one?


    these will be read from a database and created in a loop and
    could contain 10 or more text objects.


    eg: in a loop there could be 10 of these:
    <input name="productname" readonly type="text" size="10">


    how do i reference each one individually with classic asp?


    Thanks Rory - works great!!
    Last edited by ZeBula8; Jul 14th, 2006 at 09:00 PM.

  2. #2
    Lively Member johnrswanton's Avatar
    Join Date
    Nov 2004
    Location
    Ireland
    Posts
    84

    Re: load the html text controls dynamically question

    not sure exactually wat u mean but ere s sum that might help
    <%
    for c=1 to 10
    response.write("<input name='productname' readonly type='text' size='10'>")
    next

    %>

    hope it helps
    ***********
    "why do things that are suspose to bad for us taste so good, whats ur addiction"
    Kanye West
    **********

  3. #3

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: load the html text controls dynamically question

    sorry for being so vague -

    i am loading records from a database into an html table with a loop, so there could be 10 or more <input type="text"...> textbox controls within this form.


    If I give a name : <input type="text" name="product"> then in the loop
    these textboxes will all have the same name of "product".

    <table>
    <% while not rs.eof %>
    <tr>
    <td><input type="text" name="product" value="<%=rs("product")">
    </tr>
    <% wend %>
    </table>


    in the small example above each of the text objects have the same name so...
    Question is how can I identify each one individually with response.forms() ?

    As the select - option has a built in array the textbox does not.

  4. #4
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: load the html text controls dynamically question

    either

    <table>
    <% while not rs.eof %>
    <tr>
    <td><input type="text" name="<%=rs("product")%>" value="<%=rs("product")%>">
    </td></tr>
    <% wend %>
    </table>


    OR

    <table>
    <% while not rs.eof %>
    <tr>
    <td><input type="text" name="<%=rs("ID")%>" value="<%=rs("product")%>">
    </td></tr>
    <% wend %>
    </table>

    OR

    <table>
    <% c = 1: while not rs.eof: c = c+1 %>
    <tr><td>
    <input type="text" name="product<%=c%>" value="<%=rs("product")%>">
    </td></tr>
    <% wend %>
    </table>

    AND .. better coding would be this ..

    Code:
    <%
    Dim sTable
    Dim rsProduct
    Dim iCnt
    
    iCnt = 0
    sTable = ""
    sTable = sTable & "<table>" & vbCrLf
    Do Until rs.eof
        iCnt = iCnt+1
        rsProduct = rs("product")
        sTable = sTable & "<tr><td>" & vbCrLf
        sTable = sTable & "<input type=""text"" name=""product" & iCnt & """ value=""" & rsProduct & """>" & vbCrLf
        sTable = sTable & "</td></tr>" & vbCrLf
    Loop
    sTable = sTable & "</table>" & vbCrLf
    %>
    
    <%= sTable %>
    OR

    Code:
    <%
    Dim sTble, rsProd, c
    c = 0: sTble = ""
    sTble = sTble & "<table>" & vbCrLf
    Do Until rs.eof: c = c+1
        rsProd = rs("product")
        sTble = sTble & "<tr><td>" & vbCrLf
        sTble = sTble & "<input type=""text"" name=""product" & c & """ value=""" & rsProd & """>" & vbCrLf
        sTble = sTble & "</td></tr>" & vbCrLf
    Loop
    sTble = sTble & "</table>" & vbCrLf
    %>
    <%= sTble %>
    Last edited by rory; Jul 14th, 2006 at 06:51 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width