How to create dynamic checkbox by using VBscript? | Newbie | | Join Date: Aug 2008
Posts: 5
| |
Hello, I am a beginner of writing vbscript and I am now facing a question, my coding as follow - <%
-
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
-
%>
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?
|  | Moderator | | Join Date: Jan 2007 Location: logan, utah
Posts: 2,690
| | | 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: - <%
-
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 %>
Let me know if this helps.
Jared
| | Newbie | | Join Date: Aug 2008
Posts: 5
| | | 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
| | | re: How to create dynamic checkbox by using VBscript?
I have got what I want now but face another question -
<%@ 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?
|  | Moderator | | Join Date: Jan 2007 Location: logan, utah
Posts: 2,690
| | | 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
|  | Moderator | | Join Date: Jan 2007 Location: logan, utah
Posts: 2,690
| | | 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
| | | 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
| | | 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
|  | Moderator | | Join Date: Jan 2007 Location: logan, utah
Posts: 2,690
| | | 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
|  | Similar ASP / Active Server Pages bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|