Eggybread Eggybread - 5 months ago 33
Vb.net Question

How do I pass a VB variable to a JQuery

I know nothing about Javascript/Jquery but I'm wanting some numbers to spin round like an odometer and stop on the value of a variable I have in VB. I found this JQuery and Script/CSS that does the trick but I need to change the 9999 in the code below to be the value of 'points' which I have in the VB code.
Any help appreciated.

<link rel="stylesheet" href="odometer-theme-default.css" />
<script type="text/javascript" src="odometer.js"></script>

<script>
setTimeout(function(){
$('.odometer').html(9999);
}, 1000);
</script>

<p class="odometer">0000</p>

</asp:Content>

hsh hsh
Answer

Define a protected variable in your code behind:

Protected MaxValue As Integer

Give it a desirable value in page load event and use it like this inside your web form:

<%=MaxValue %>

or you can define and manipulate it in the form it self like this:

<link rel="stylesheet" href="odometer-theme-default.css" />
<script type="text/javascript" src="odometer.js"></script>

<script>
   <% Dim MaxValue as Integer = 123 %>
   setTimeout(function(){
      $('.odometer').html(<%=MaxValue %>);
   }, 1000);
</script>

<p class="odometer">0000</p>