Connecting Tech Pros Worldwide Forums | Help | Site Map

How to create dynamic checkbox by using VBscript?

Newbie
 
Join Date: Aug 2008
Posts: 5
#1: Aug 8 '08
Hello, I am a beginner of writing vbscript and I am now facing a question, my coding as follow
Expand|Select|Wrap|Line Numbers
  1. <%
  2. dim ID(5)
  3. dim value(5)
  4. dim count = 5
  5. dim i = 0
  6. while i<count
  7. response.write("<form>")
  8. response.write("<input type = checkbox ID = "+ID(i)+" value = "+value(i)+">")
  9. response.write(</form>
  10. end while
  11. %>
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?

jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#2: Aug 9 '08

re: How to create dynamic checkbox by using VBscript?


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:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. dim ID(5)
  3. dim value(5)
  4. dim count = 5
  5. dim i
  6. for i = 0 to count %>
  7.    <form>
  8.       <input type="checkbox" ID="<%=ID(i)%>" value="<%=value(i)%>">
  9.    </form>
  10. <%
  11. next %>
Let me know if this helps.

Jared
Newbie
 
Join Date: Aug 2008
Posts: 5
#3: Aug 10 '08

re: How to create dynamic checkbox by using VBscript?


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
Newbie
 
Join Date: Aug 2008
Posts: 5
#4: Aug 10 '08

re: How to create dynamic checkbox by using VBscript?


I have got what I want now but face another question
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="True" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  4.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5.  
  6. <script runat="server" language=vbscript>
  7.  
  8.  
  9.     Sub Test(ByVal sender As Object, ByVal e As EventArgs)
  10.         Dim i
  11.         For i = 0 To 4
  12.             Dim name = "ID" + i.ToString
  13.             If name.Checked Then
  14.                 Response.Write(name.Value)
  15.             End If
  16.         Next
  17.     End Sub
  18. </script>
  19.  
  20. <html >
  21.  
  22. <head id="Head1" runat="server">
  23.     <title> CheckBoxList Example </title>
  24.  
  25. </head>
  26.  
  27. <body>
  28. <form runat="server" action="">
  29. <%
  30.            Dim ID() = {"John", "Peter", "Tom", "Herman", "Mary"}
  31.            Dim value() = {1, 2, 3, 4, 5}
  32.            Dim count = 5
  33.            Dim i
  34.            For i = 0 To count - 1%>
  35.  
  36. <!--      * --><input type="checkbox" id= "<%="ID"+i.tostring%>" value="<%=ID(i).toString%>" runat="server"/> <%=ID(i).ToString()%>
  37.  
  38.  
  39. <%
  40. next %>
  41.        <input type ="button" value ="Send" runat ="server" onserverclick="Test" />
  42. </form>
  43. </body>
  44.  
  45. </html>
  46.  
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?
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#5: Aug 11 '08

re: How to create dynamic checkbox by using VBscript?


Quote:

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
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#6: Aug 11 '08

re: How to create dynamic checkbox by using VBscript?


Quote:

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
Newbie
 
Join Date: Aug 2008
Posts: 5
#7: Aug 28 '08

re: How to create dynamic checkbox by using VBscript?


Quote:

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.
Newbie
 
Join Date: Aug 2008
Posts: 5
#8: Aug 28 '08

re: How to create dynamic checkbox by using VBscript?


Quote:

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.SelectNodes("/Books/Book/Title").count<-----I forget whether it is correct

dim values(count)
dim i
for i = 0 to count
'further coding
next
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#9: Aug 29 '08

re: How to create dynamic checkbox by using VBscript?


Quote:

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
Reply