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!

Passing Text Variables in VBScript 1

Status
Not open for further replies.

JohnBeals

Programmer
Feb 26, 2002
49
US
I am having a problem passing a text variable. I'm doing something wrong, but don't know what. Here's the code...

1 Dim FormNum
2 Dim FormValue
3 Sub JobIDSubmit_onclick
4 Dim JobID
5 call ValidateForm(0, JobID)
6 JobID = document.forms(0).JobID.value
7 window.navigate("SelectSchedDecision.cfm?ID=" & JobID)
8 End Sub

10 Sub ValidateForm(FormNum, FormValue)
11 if not len(trim(document.forms(FormNum).FormValue.value)) > 0 then
12 strValMessage = "You must enter a value."
13 document.forms(FormNum).FormValue.focus()
14 exit Sub
15 end if
16 End Sub

What I get is the error message:
Error: Object doesn't support this property or method: 'document.forms(...).FormValue'

Which tells me my variable FormValue is being taken literally on line 11. How do I get the variable FormValue to convert to the text JobID on line 11?

Thanks,
John
 
Weird combo: VBScript at the client and ColdFusion at the server.

Well your problem is that you are trying to use a variable (FormValue) in a place where only a property can be used (such as JobID, which I assume is a form element such as an <input type=text> element).

You might try passing in the index of this element within the items collection of document.forms( ) and then use document.forms(FormNum).items(ElemIndex).value as one possibility.

Otherwise you are stuck with &quot;preinterpreting&quot; the expression using the Eval function as in:

Eval(&quot;document.forms(FormNum).&quot; & FormValue & &quot;.value&quot;)

But you must pass &quot;JobID&quot; (alias FormValue) in as a string, not as an object, so Eval munches on a string that gets built up to &quot;express&quot; what you want evaluated.

Hope this helps!
 
Be reminded that you can access an object thru a collection using the Index or ID/Name. In your case, you'll need to access &quot;JobID&quot; thru the elements collection, ISO, as a property.

Sub ValidateForm(FormNum, FormValue)
document.forms(FormNum).Elements(FormValue).focus()
End SUb

Call ValidateForm(0,10)
Call ValidateForm(0,&quot;JobID&quot;)
Call ValidateForm(&quot;MyFormName&quot;,&quot;JobID&quot;)
Jon Hawkins
 
Thanks both of you. I went with the Elements solution and it works great.

John
PS: Yes it is kinda weird using both Cold Fusion and VBScript, but it does have some advantages as long as I remember what's running where!
JB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top