Results 1 to 4 of 4

Thread: Control array in VBScript

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    Montréal, Québec Canada
    Posts
    202

    Control array in VBScript

    Hail,

    If I have 3 text boxes with the same name that I put in an array:

    <input name='txtInput[]' size='5'>
    <input name='txtInput[]' size='5'>
    <input name='txtInput[]' size='5'>

    How can I in a vbscript refer to #2 for example? I thought I could say something like:

    <SCRIPT LANGUAGE="VBScript">
    <!--
    Sub B1_OnClick
    msgbox txtInput(2).value
    End Sub
    -->
    </SCRIPT>

    But it doesn't work, this might be fairly obvious, can someone help me out?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Control array in VBScript

    That code could work in VB6.

    Here, though, all elements must have a different name/id, and so you cannot have any control array in your html pages. What are you trying to accomplish that requires a control array?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    Montréal, Québec Canada
    Posts
    202

    Re: Control array in VBScript

    Quote Originally Posted by mendhak
    That code could work in VB6.

    Here, though, all elements must have a different name/id, and so you cannot have any control array in your html pages. What are you trying to accomplish that requires a control array?
    Basically, I want to display three fields from a database that match a certain criteria. So let's say I have name, email and phone in my DB and I want to display that in text boxes for records added in the past week. Using PHP, I retrieve the info and create a simple HTML form and basically show the three fields for each record. Then info can be changed and submitted, and I found in PHP that to do so I have to put the [] with the control name to create an array, which works fine. But now let's say I want to put some validation on those text boxes, I can't? If it works for HTML and PHP, why won't it cooperate with VBscript?

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Control array in VBScript

    With ASP, in your loop, you can generate your INPUT elements like so:

    <input id=MyTextBox<% =i %>

    where i is an incremented variable in your loop. You would then access the values/perform validation similarly, by concatention.

    Although the square brackets seem valid enough as a value for name in the input element, I do not know how one would implement the same thing in ASP.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width