I have a session variable (ClientID) that i want to pass into Javascript which will in turn send out to my 3rd party tracking company. I’ve tried several methods of passing the data. I tried using <%= Session(“ClientID”) %>. But I read you cannot do it this way as Javascript is client side and session in server side. So I read you could create a hidden form field and then call the element id in the javascript. This did not work either, but I think it might have been bad syntax.
I know the ClientID is being grabbed from the database because I can print it to the page. Just not to the Javascript.
Is it a matter of syntax? Or am I just doing it wrong. I could not find much in Google. Mostly it was on how to do it the other way, passing javascript variables to ASP sessions. Any help would be appreciated. Thanks.
Here is the javascript:
<script type="text/javascript">
var _mTrack = _mTrack || [];
_mTrack.push(['addTrans', {
orderId : "<%= Session("clientID") %>",
total : ,
tax : ,
shipping : ,
}]);
_mTrack.push(['processOrders']);
(function() {
var mClientId = '[123456789]';
var mProto = ('https:' == document.location.protocol ? 'https://' : 'http://');
var mHost = 'tracker.xxx.com';
var mt = document.createElement('script'); mt.type = 'text/javascript'; mt.async = true; mt.src = mProto + mHost + '/tracker/async/' + mClientId + '.js';
var fscr = document.getElementsByTagName('script')[0]; fscr.parentNode.insertBefore(mt, fscr);
})();
</script>
<noscript>
<img src="https://tracker.xxx.com/tp?act=2&cid=[123456789]&script=no" >
</noscript>
I also tried using this hidden form and the javascript:
<form style='display:none;' name='ClientID'>
<input type="hidden" name="ClientID" value="<%= Session("ClientID") %>">
</form>
orderId : '<DCCClientID2>',