I'm trying to make a button appear if condition "isauthenticated" is "true".
used this as a reference, but not sure what's wrong with my code.
<button id="authentic" type="hidden">test</button>
<script>
window.onload = function() {
var logedIn = ('{{isauthenticated}}')
if(logedIn == "true") {
document.getElementById('authentic').style.display = 'block';
} else {
document.getElementById('authentic').style.display = 'none';
}
}
</script>
I'm trying to make a button appear if condition "isauthenticated" is "true".
used this as a reference, but not sure what's wrong with my code.
<button id="authentic" type="hidden">test</button>
<script>
window.onload = function() {
var logedIn = ('{{isauthenticated}}')
if(logedIn == "true") {
document.getElementById('authentic').style.display = 'block';
} else {
document.getElementById('authentic').style.display = 'none';
}
}
</script>
Share
Improve this question
edited May 23, 2017 at 11:44
CommunityBot
11 silver badge
asked Nov 7, 2013 at 16:47
user2755801user2755801
531 gold badge3 silver badges9 bronze badges
3
-
10
What's
{{isauthenticated}}
? Set by the server? Ractive.js template variable? – Zeta Commented Nov 7, 2013 at 16:48 - 1 check logedIn against true and not "true" – Anto Jurković Commented Nov 7, 2013 at 16:50
- 2 Did you try to log to console logedIn value? – Adriano Repetti Commented Nov 7, 2013 at 16:50
3 Answers
Reset to default 3Ok Guys, sorry for the bad question. This is what I was looking for
<script>
var isAuth = ('{{ user.isauthenticated}}');
if (isAuth) true;
document.getElementById("menuProfile").style.display="block";
document.getElementById("showProfile").style.display="none";
</script>
if logedIn
is a boolean value you need to remove the "
's from the if(logedIn == "true") {
line
or just check:
if(logedIn) {...
Please refer to Boolean Javascript documentatiion:
If the Boolean object has no initial value, or if the passed value is one of the following:
0,-0,null,"",false,undefined,NaN the object is set to false. For any other value it is set to true (even with the string "false")!
see what value does logedIn have before the if!