How to create dynamic checkbox by using VBscript?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TingYan
    New Member
    • Aug 2008
    • 5

    How to create dynamic checkbox by using VBscript?

    Hello, I am a beginner of writing vbscript and I am now facing a question, my coding as follow
    [code=asp]<%
    dim ID(5)
    dim value(5)
    dim count = 5
    dim i = 0
    while i<count
    response.write( "<form>")
    response.write( "<input type = checkbox ID = "+ID(i)+" value = "+value(i)+ ">")
    response.write( </form>
    end while
    %>[/code]The output only displays checkboxs with no value and the checkbox can not be accessed even I check it , is there anything wrong with my coding? And is there any solution (or other method) can satisfy the same situation?
    Last edited by jhardman; Aug 9 '08, 10:18 PM. Reason: added code tags - please note button marked #
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    I stop using response.write when I have a long section of HTML code, especially if there are a lot of quote marks. I would write it more like this:
    [code=asp]<%
    dim ID(5)
    dim value(5)
    dim count = 5
    dim i
    for i = 0 to count %>
    <form>
    <input type="checkbox" ID="<%=ID(i)%> " value="<%=value (i)%>">
    </form>
    <%
    next %>[/code]Let me know if this helps.

    Jared

    Comment

    • TingYan
      New Member
      • Aug 2008
      • 5

      #3
      Thank you for your help, I had tried the coding but the result caused the same problem which the checkbox are displayed with no value, and no response if I checked them

      Comment

      • TingYan
        New Member
        • Aug 2008
        • 5

        #4
        I have got what I want now but face another question
        Code:
        <%@ Page Language="VB" AutoEventWireup="True" %>
        
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        
        <script runat="server" language=vbscript>
        
        
            Sub Test(ByVal sender As Object, ByVal e As EventArgs)
                Dim i
                For i = 0 To 4
                    Dim name = "ID" + i.ToString
                    If name.Checked Then
                        Response.Write(name.Value)
                    End If
                Next
            End Sub
        </script>
        
        <html >
        
        <head id="Head1" runat="server">
            <title> CheckBoxList Example </title>
           
        </head>
        
        <body>
        <form runat="server" action="">
        <%
                   Dim ID() = {"John", "Peter", "Tom", "Herman", "Mary"}
                   Dim value() = {1, 2, 3, 4, 5}
                   Dim count = 5
                   Dim i
                   For i = 0 To count - 1%>
           
        <!--      * --><input type="checkbox" id= "<%="ID"+i.tostring%>" value="<%=ID(i).toString%>" runat="server"/> <%=ID(i).ToString()%>
              
           
        <%
        next %>
               <input type ="button" value ="Send" runat ="server" onserverclick="Test" />
        </form>
        </body>
        
        </html>
        The problem located in the *
        the warining message shows it is not allow to use <%%> symbol whether I am using it is runat server

        Is there any solution to sort this problem?

        Comment

        • jhardman
          Recognized Expert Specialist
          • Jan 2007
          • 3405

          #5
          Originally posted by TingYan
          Thank you for your help, I had tried the coding but the result caused the same problem which the checkbox are displayed with no value, and no response if I checked them
          Well this code doesn't assign a value to the value() array. what values do you want in the value() array?

          Jared

          Comment

          • jhardman
            Recognized Expert Specialist
            • Jan 2007
            • 3405

            #6
            Originally posted by TingYan
            The problem located in the *
            the warining message shows it is not allow to use <%%> symbol whether I am using it is runat server

            Is there any solution to sort this problem?
            This looks like a combination of ASP and ASP.NET, the two are not compatible. Are you trying to write ASP (.asp file extension with VBScript) or ASP.NET (.aspx file extension with VB)?

            Jared

            Comment

            • TingYan
              New Member
              • Aug 2008
              • 5

              #7
              Originally posted by jhardman
              This looks like a combination of ASP and ASP.NET, the two are not compatible. Are you trying to write ASP (.asp file extension with VBScript) or ASP.NET (.aspx file extension with VB)?

              Jared
              YUP....I am trying to write asp.net however I am not good at using the interal tools provided, so I try do use vbscript to create the interface. But it seems hard to create the dynamic checkbox.

              Comment

              • TingYan
                New Member
                • Aug 2008
                • 5

                #8
                Originally posted by jhardman
                Well this code doesn't assign a value to the value() array. what values do you want in the value() array?

                Jared
                the value is dynamic too, as I would like to extract the data from the XML file, such as the title of books in xml document. for example, if there are 2 titles found , there will be a variable called "count" to hold it then using the array to store the values

                E.g

                count = xmlDoc.SelectNo des("/Books/Book/Title").count<-----I forget whether it is correct

                dim values(count)
                dim i
                for i = 0 to count
                'further coding
                next

                Comment

                • jhardman
                  Recognized Expert Specialist
                  • Jan 2007
                  • 3405

                  #9
                  Originally posted by TingYan
                  YUP....I am trying to write asp.net however I am not good at using the interal tools provided, so I try do use vbscript to create the interface. But it seems hard to create the dynamic checkbox.
                  Before we go any further you will need to decide which you are going to use. You can not write ASP.NET with VBScript, you will need to use VB.NET in ASP.NET or VBScript in "classic" ASP. The languages are similar, but not identical. Also, the methods for creating dynamic checkboxes are very different. in ASP.NET you can bind a list of checkboxes to the XML data, but in "classic" ASP you would loop through the XML data and create a new checkbox for each row. Does this make sense?

                  Jared

                  Comment

                  Working...