I ran across the need to get the user's Rank into some Javascript I was writing, and I thought I'd share it.
.
.
.
<body>
<!--System:IfRank:1--><div id="Rank1" style="display:none"></div><!--System:EndIfRank-->
<!--System:IfRank:2--><div id="Rank2" style="display:none"></div><!--System:EndIfRank-->
<!--System:IfRank:3--><div id="Rank3" style="display:none"></div><!--System:EndIfRank-->
<!--System:IfRank:4--><div id="Rank4" style="display:none"></div><!--System:EndIfRank-->
<!--System:IfRank:5--><div id="Rank5" style="display:none"></div><!--System:EndIfRank-->
<!--System:IfRank:6--><div id="Rank6" style="display:none"></div><!--System:EndIfRank-->
<!--System:IfRank:7--><div id="Rank7" style="display:none"></div><!--System:EndIfRank-->
<!--System:IfRank:8--><div id="Rank8" style="display:none"></div><!--System:EndIfRank-->
.
.
.
</body>
Javascript function to return the rank (you can make it either external or inline):
<script type="text/javascript">
function getRank()
{
var rank = 1000;
var rank1 = document.getElementById("Rank1");
var rank2 = document.getElementById("Rank2");
var rank3 = document.getElementById("Rank3");
var rank4 = document.getElementById("Rank4");
var rank5 = document.getElementById("Rank5");
var rank6 = document.getElementById("Rank6");
var rank7 = document.getElementById("Rank7");
var rank8 = document.getElementById("Rank8");
if (rank1)
{
rank = 1;
}
else if (rank2)
{
rank = 2;
}
else if (rank3)
{
rank = 3;
}
else if (rank4)
{
rank = 4;
}
else if (rank5)
{
rank = 5;
}
else if (rank6)
{
rank = 6;
}
else if (rank7)
{
rank = 7;
}
else if (rank8)
{
rank = 8;
}
return (rank);
}
(edited, somehow the message entry widget decided I was done early
Yes, there was probably an easier way to do it. Yes, I'm a programmer and I cringe at that code. It works, though.
D