Reputation: 283
If I have a html document with this:
<p onclick="hiho('@name')"> clicky </p>
<script>
function hiho(namevar){
var1 = @Names.find.where().eq("name", namevar).findUnique();
if( var1 != null){
alert("HIHO");
}
}
</script>
How do I use the JavaScript variable?
Play won't compile properly because inside
var1 = @Names.find.where().eq("name", namevar).findUnique();
it cannot find the value of namevar.
Upvotes: 0
Views: 554
Reputation: 13096
One, pretty straightforward, solution could be:
<p onclick="hiho('@name')"> clicky </p>
<script>
var map = {
'@name': '@Names.find.where().eq("name", name).findUnique()'
};
function hiho(namevar){
var value = map[namevar];
if( value != null){
alert("HIHO: " + value);
}
}
</script>
Supposing that the name variables are strings.
Upvotes: 2