Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string

Status
Not open for further replies.

cjkenworthy

Programmer
Sep 13, 2002
237
GB
I am trying to read values from multiple fields into one single string strTERMNO. The fields come from a form:

<form>
txttermno1
txttermno2
txttermno3
txttermno N etc ..
</form>

The number of txttermno's change dynamically, so there is no set number.

I want strTERMNO to be set to a comma seperated string:

strTERMNO = txttermno1's value, txttermno2's value ...

How would I do a loop to do this, given that I can pass this number of txttermno's in a variable 'varCounter' ?


thanks, chris.
 
I think you can treat text boxes as a control array. I have a bit of VB code that does something like that:

For lngLocalI = 0 To frmForm.Controls.Count - 1
If Left(frmForm.Controls(lngLocalI).Name, 3) = &quot;txt&quot; Then
lngLocalJ = Len(frmForm.Controls(lngLocalI).Name)
strLocala = Mid(frmForm.Controls(lngLocalI).Name, 4, lngLocalJ)
If Len(adorsLocal.Fields(strLocala)) > 0 Then
strValue = ConvertValueUser(adorsLocal.Fields(strLocala).Name, adorsLocal.Fields(strLocala))
frmForm.Controls(lngLocalI).Text = strValue
frmForm.Controls(lngLocalI).ToolTipText = strValue
Else
frmForm.Controls(lngLocalI) = Space(0)
End If
End If
Next
 
If all you need are the formfield values, probably in the order they appear on the form, just name each field the SAME THING and in your code you can retrieve them as
Code:
fldName(0)
through
Code:
fldName(n-1)
.

To VBScript they look like an array.
 
Unfortunately I cannot do this, as the fields require unique names for some clever javascript I wrote to validate input.

 
Hmmm... then you can just use the form's elements collection, right?
Code:
<HTML>
  <HEAD>
    <TITLE>Form Fields</TITLE>
    <SCRIPT LANGUAGE=&quot;VBScript&quot;>
      Sub btnGo_onClick
        Dim fldMember, strContent

        For Each fldMember In frmEntry.elements
          If LCase(fldMember.type) = &quot;text&quot; Then
            strContent = strContent & &quot;, &quot; & fldMember.name & &quot;=&quot; & fldMember.value
          End If
        Next
        strContent = Mid(strContent, 3)
        MsgBox strContent
      End Sub
    </SCRIPT>
  </HEAD>
  <BODY onLoad=&quot;VBScript: frmEntry.fld000.focus&quot;>
    <FORM name=&quot;frmEntry&quot;>
      <INPUT type=&quot;text&quot; name=&quot;fld000&quot;><BR>
      <INPUT type=&quot;text&quot; name=&quot;fld001&quot;><BR>
      <INPUT type=&quot;text&quot; name=&quot;fld002&quot;><BR>
      <INPUT type=&quot;button&quot; name=&quot;btnGo&quot; value=&quot;Go&quot;>
    </FORM>
  </BODY>
</HTML>
The fields can be named whatever you want of course. You will need to have some way to pick out just those elements you want however. Here I grabbed all the <INPUT type=&quot;text&quot;> elements.
 
I was going to retrieve the values in the .asp file to where I post the form to using:

dim strTERMNO

dim formcounter
dim J

formcounter = Request.Form(&quot;hdnrecords&quot;)

for J=1 to formcounter

strTERMNO = strTERMNO & Request.Form(&quot;txttermno&quot; & J) & &quot;, &quot;
next

I used 'J=1' because the first field is called txttermno1, 'hdnrecords' is the number of fields.

This doesn't appear to work much though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top