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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass Vbscript variable to JavaScript function

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
Hi,

I have a form.
When I retrieve the form's values I use Vbscript

<%

Dim RequestType
Dim EmployeeID
Dim RequestorID

RequestType=Request.Form(&quot;RequestType&quot;)
EmployeeID=Request.Form(&quot;recip_employee_no&quot;)
RequestorID=Request.Form(&quot;request_employee_no&quot;)


%>

Then goes the HTML part and then JavaScript function.
When I use RequestType variable in my JavaScript function, I get an error RequestType is not defined. Is that because the VbScript variable are not visible for the JavaScript

How to go around this problem

Thanks
 
<script>

myVar = &quot;<%=request(&quot;variableName&quot;)%>&quot;

</script> Get the Best Answers! faq333-2924
&quot;A witty saying proves nothing.&quot; - Voltaire
mikewolf@tst-us.com
 
Yes. The VBScript variables exist on the server, the javascript variables exist on the client. An easy way to transfer values from your VBScript to your javascript is to simply write them inoto the javascript exactly the way you would write something into your html:
Code:
<script language=&quot;JavaScript&quot;>
<!--
var x = <%=RequestType%>
//-->
</script>

Since the javascript won't get executed until you it gets to the client, you can write anything you want to into the javascript section from your VBScript.

-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top