How to put HTML code in JavaScript if() statement

I've looked all over the web for an answer to this, and all I can really find directed to my actual question is 'ajax' and I'm already using it, but that don't say what in it to use!

Here's my problem: I have HTML code(specifically a table with a form inside of it, but that doesn't matter), and I need the code to depend on a JavaScript variable grabbed from a cookie.

In the beginning of the form, naturally, I'd put my declarations for when the page loads:

<script type="text/javascript">
    var login = 0;
    var myusername;
    var saves = [];
    $(document).ready(function() {
        if (jQuery.cookie('savedata')) {
            savedstats = jQuery.cookie('savedata').split('|');
            login = parseInt(savedstats[0]);
            myusername = parseInt(savedstats[1);
        } else {
            login = 0;
        }
    });
</script>

And I've tried many different ways, but.. No avail.

Upvotes: 0

Views: 3302

Answers (1)

Nhu Trinh
Nhu Trinh

Reputation: 13956

<script type="text/javascript">
    var login = 0;
    if (login == 0){
        document.write('<li><a title="home"....</li>');
    }else{
        document.write('<li>Not valid</li>');
</script>

Is that what you want?

PS, this is a very very bad design

Upvotes: 1

Related Questions