Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    South East UK. 35 miles east of London, in sight of the River Thames.
    Posts
    300
    Thanks
    10
    Thanked 0 Times in 0 Posts

    response.write asp code that executes

    Hi All,

    I am displaying the contents of 3 fields from an access database using the following code:

    <tr><td height="20"></td>
    <tr><td bgcolor="#eeeeee">Page 1</td><td><TEXTAREA WRAP=PHYSICAL ID="page1" NAME="page1" ROWS=20 COLS=120 ><%=(ors.Fields.Item("page1").Value)%></TEXTAREA></td></tr>
    <tr><td height="20"></td>
    <tr><td bgcolor="#c0c0c0">Page 2</td><td><TEXTAREA WRAP=PHYSICAL ID="page2" NAME="page2" ROWS=20 COLS=120 ><%=(ors.Fields.Item("page2").Value)%></TEXTAREA></td></tr>
    <tr><td height="20"></td>
    <tr><td bgcolor="#eeeeee">Page 3</td><td><TEXTAREA WRAP=PHYSICAL ID="page3" NAME="page3" ROWS=20 COLS=120 ><%=(ors.Fields.Item("page3").Value)%></TEXTAREA></td></tr>
    <tr><td height="20"></td>

    This works perfectly.

    I'm now trying to be clever and replace the above code with a loop. This almost works:

    <%
    Dim i
    For i=1 to 3

    response.write "<tr><td height=""20""></td>"
    response.write "<tr><td bgcolor=""#eeeeee"">Page "&i&"</td><td><TEXTAREA WRAP=PHYSICAL ID=""page"&i&""" NAME=""page"&i&""" ROWS=""20"" COLS=""120"" >"
    response.write "<%=(ors.Fields.Item(""page"&i&""").Value)% >"
    response.write "</TEXTAREA></td></tr>"

    next
    %>

    The problem is the end of this 3rd row:

    response.write "<%=(ors.Fields.Item(""page"&i&""").Value)% >"

    If I close up the space between the " % " and the " > " the script doesn't work.

    How can I get this line of code [response.write "<%=(ors.Fields.Item(""page"&i&""").Value)% >"] to produce this [><%=(ors.Fields.Item("page2").Value)%>]?

    Regards

    Gary

  • #2
    New Coder
    Join Date
    Mar 2005
    Posts
    50
    Thanks
    0
    Thanked 2 Times in 2 Posts
    hi gary
    you could try something like this.
    i didn't test it and it depends what fields you have in your db.
    If you have two fields say one for the name and then one for the textarea content then you could loop through it any number of ways.
    I always think its better not to hard code a loop value with the recordset object (unless your always only pulling 3 items)

    Code:
    while not ors.EOF 
    Response.Write ("<tr><td bgcolor='#eeeeee'>"& _
                        ors("pageName") & "</td>" &vbcrlf & _
                        "<td><TEXTAREA WRAP=PHYSICAL ID='" &_
                        ors("pageName") & "' NAME='" & ors("pageName") & _
                        "' ROWS='20' COLS='120'>" & ors("page") & _
                        "</TEXTAREA></td></tr>")
            ors.MoveNext
    wend

    hth

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    South East UK. 35 miles east of London, in sight of the River Thames.
    Posts
    300
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Hi Chud,

    Thanks for the help. It produced and interesting result in that it displayed both the rendered html and the code in a textarea.

    I'll experiment with this.

    Thanks again.

    Regards

    Gary

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Location
    South East UK. 35 miles east of London, in sight of the River Thames.
    Posts
    300
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Hi Chud,

    OK, got this far:

    <%
    Dim i
    For i=1 to 3
    Response.Write "<tr><td bgcolor=""#eeeeee"">Page " & i & "</td><td><TEXTAREA WRAP=PHYSICAL ID=""Page" & i & """ NAME=""Page" & i & """ ROWS=""20"" COLS=""120"">" & ors("'"page"'" "'"&i&"'") & "</TEXTAREA></td></tr>"
    next
    %>

    The code written by this is correct excetp for the part in bold. I'm trying to loop through the fields by incrementing the field name - page1, page2, etc.

    I need it to write:

    "& ors("page1") & "
    "& ors("page2") & "

    and so on.

    Regards

    Gary

  • #5
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    OK, got this far:

    <%
    Dim i
    For i=1 to 3
    Response.Write "<tr><td bgcolor=""#eeeeee"">Page " & i & "</td><td><TEXTAREA WRAP=PHYSICAL ID=""Page" & i & """ NAME=""Page" & i & """ ROWS=""20"" COLS=""120"">" & ors("'"page"'" "'"&i&"'") & "</TEXTAREA></td></tr>"
    next
    %>

    The code written by this is correct excetp for the part in bold. I'm trying to loop through the fields by incrementing the field name - page1, page2, etc.

    from your code example, you have database fields with the same name except for a numeric identifier at the end like page1, page2, page3

    using two quotes like so "" says that you want to display a single quote on the page. Generally speaking you only need to use quote apostrophe quote when you are inside a sql statement working with a datatype that isn't numeric. When you want to return the value of a column in a recordset then you just use a single quote around the name of the column. Since you want to loop through the different like named columns you would use the single quote around the name plus the & and the variable that holds the value so you end up with

    Code:
    <%
    Dim i
    For i=1 to 3
         Response.Write "<tr><td bgcolor=""#eeeeee"">Page " & i & "</td><td><TEXTAREA WRAP=PHYSICAL ID=""Page" & i & """ NAME=""Page" & i & """ ROWS=""20"" COLS=""120"">" & ors("page"&i) & "</TEXTAREA></td></tr>"
    next
    %>


    you could also do it like this

    Code:
    Dim i, sPage
    For i=1 to 3
        sPage = "page" & i  
        Response.Write "<tr><td bgcolor=""#eeeeee"">Page " & i & "</td><td><TEXTAREA WRAP=PHYSICAL ID=""" sPage & """ NAME=""" & sPage & """ ROWS=""20"" COLS=""120"">" & ors(sPage) & "</TEXTAREA></td></tr>"
    next
    Last edited by miranda; 04-09-2006 at 03:18 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
    •