1

I'm editing a previous coworkers code so I don't know 100% how it works. It is written in Javascript and ASP. Here is the current code

<script>
    var sessionDone = 0;
    <% if session(ReturnSessionID()) = 1 then %>
        sessionDone = 1;
    <% endif %>
</script>

and then there is some html with links, like this:

<a href='#'>link</a>

What I want is this:

<script>
    var sessionDone = 0;
    var counter = 0;

    $('a').click( function() {
        sessionDone = 1;

        if (counter == 3) {
            <% session(ReturnSessionID()) = 1 %>
        } else {
            counter += 1;
        }
    });
</script> 

When I do this, the line

<% session(ReturnSessionID()) = 1 %>

automatically gets run even if the if statement isn't true and even if I did not click a link. How do I make the link only get executed when counter is 3?

Note: I do not know ASP and I don't really need to learn it, this is the only time I will be using it.

user2817200
  • 1,097
  • 2
  • 18
  • 38
  • Duplicate of [Reference: Why does the PHP (or other server side) code in my Javascript not work?](http://stackoverflow.com/questions/13840429/reference-why-does-the-php-or-other-server-side-code-in-my-javascript-not-wor) – Quentin Feb 11 '14 at 15:21

1 Answers1

0

ASP is being executed on the server. The resulting HTML/JavaScript is being sent to the browser and then there the JavaScript is being executed. You cannot mix it like this.

When you want client-side JS to update a server-side variable, you have to make a request from the client to the server, which tells the server to update the variable.