 |
| VB How-To Ask your "How do I do this with VB?" questions in this forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 4th, 2007, 11:50 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
|
|
VBScript to list Textboxes on page
Sorry to post this here, but there still doesn't seem to be a VBSCRIPT forum, or if there is, I couldn't find it. This seems like a simple quesation, yet I cannot find any information anywhere on how to do this.
I have a dynamically created form containing one or more text boxes and textarea fields. I would like to obtain the value from each in a loop without directly referencing the field by name. What is the equivalent of this in VBSCRIPT:
for each form field
if this is a text box or a text area field
reference the value of the field
end if
next
|
|

October 4th, 2007, 03:18 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
I believe you need to get each element in the formâs .Controls collection.
For each one, check itâs control type to exclude labels, buttons, et al.
Given the type, use the appropriate property (.Text? .Value?) to reference the contents.
|
|

October 4th, 2007, 03:26 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
|
|
I aready surmised as much and I know I need VALUE. I was rather hoping for some functioning code indicating exactly what the method for TYPE is in VBScript as I can find no examples on-line anywhere.
|
|

October 4th, 2007, 05:11 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
Well, I would have to do the same thing you could do. Create a simple form without much on it, loop through the controls collection, and use the TypeName() function to list the type of everything. It should then become apparent whatâs what.
|
|

October 5th, 2007, 07:10 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
|
|
TypeName appears to tell me whether a variable or value is a string, integer, null, and so forth. I am looking for a way to tell whether an HTML form field is a text box, text area, radio button, check box, etc.
|
|

October 5th, 2007, 08:28 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
|
|
For enquiring minds and anybody else trying to figure out how to do this, here is what I was looking for:
dim i
For i = 0 to myform.Elements.length-1
if instr(myform.Elements(i).type,"text") then
do whatever
end if
Next
The reference to the .LENGTH property wasn't especially intuitive to an old VBer like myself. I expected a .COUNT property, and indeed several sites suggested as much, but IE returns "Object doesn't support this property or method: 'myform.Elements.count'". .LENGTH was just a lucky guess.
I am, incidentally, soliciting for a hit fund for whomever on the VBScript committee thought that .LENGTH made more sense than .COUNT when dealing with the number of elements in an array! :(
And the .TYPE property is the key to identifying the kind of field currently under examination. It returns "text" for text boxes and "textarea" for text areas.
I knew it would be easy to do once I figured out the right properties to use!
|
|
 |