user1345883
user1345883

Reputation: 451

Jquery won't recognize variable in a <%=%> scriptlet tag

I have following (simplified) code:

$("select").change(function(){
    <%String lookupcode = "test";%>
    var code= <%=lookupcode%>;
    alert(code);
}

What is wrong with this code, why won't he alert the code?

Upvotes: 2

Views: 217

Answers (1)

StuartLC
StuartLC

Reputation: 107317

As lookupcode is a string variable, you need to surround the embedded variable in quotes in your javascript:

var code= '<%=lookupcode%>';

Upvotes: 7

Related Questions