473,322 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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
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?
Aug 8 '08 #1
8 16216
jhardman
3,406 Expert 2GB
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
Aug 9 '08 #2
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
Aug 10 '08 #3
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?
Aug 10 '08 #4
jhardman
3,406 Expert 2GB
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
Aug 11 '08 #5
jhardman
3,406 Expert 2GB
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
Aug 11 '08 #6
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.
Aug 27 '08 #7
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
Aug 27 '08 #8
jhardman
3,406 Expert 2GB
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
Aug 29 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: bobby1041 | last post by:
Hi All! I am trying to make several fields in a HTML form validated, but only when a dynamic checkbox is selected. I am not sure how to do this. Here is a snippet of the dynamic checkbox...
1
by: savvy | last post by:
I'm comparing two strings and trying to check a dynamic checkbox when its true on pageload , but i dont know why i'm not able to do that on page load, when i click some other links and come back to...
3
by: James Wong | last post by:
Dear Sir, I want to create some dynamic checkbox controls into the table. How can I get these controls after the form is submitted. ----------------------------------------------------- e.g....
0
by: iskyline | last post by:
hi there, I'm working with HTA's and vbscripting, and i've managed to get a list of all the text files from a parent folder defined by the user and displayed the information on the HTA window with...
5
by: lucius | last post by:
Can someone provide a sample of how to add a new CheckBox control to an ASP.NET page, dynamically completely in code-behind? I am having a problem understanding which event should handle the...
3
by: Raymond | last post by:
I am having a problem about the dynamic checkbox Private Sub Page_Load Me.NumberOfChkControls = 0 Dim cbCheckBox As New CheckBox cbCheckBox.Text = .Id.ToString cbCheckBox.ID = "ControlID_" +...
1
by: iderocks | last post by:
Hi All, I created a dynamic checkbox in ASP .Net inside a Button1_Click event method (outside the page_load event) and performed the event handling method for the CheckedChanged event and when I...
1
by: vivek kapile | last post by:
Title:Dynamically adding table row with a checkbox using JavaScript Author:Vivek Kapile Email:snipped Language:JavaScript Platform:JavaScript in ASP.net Technology:Used in ASP.net...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.