0

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.

5
  • where should the html get added? Commented Jun 10, 2013 at 3:34
  • 3
    it is as simple as $('some-element').append('some-html') Commented Jun 10, 2013 at 3:35
  • 6
    Where do you have the HTML code? How should it depend on the cookie? Why do you think this should be done with JS? Commented Jun 10, 2013 at 3:36
  • Do you want to insert the username into the page? Something like $('.username').html(myusername) and the HTML would be <span class="username"></span> Commented Jun 10, 2013 at 3:46
  • I don't understand what you are asking. Please make your question more clear. Commented Jun 10, 2013 at 6:17

1 Answer 1

1
<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

Sign up to request clarification or add additional context in comments.

2 Comments

Not really... Here's a photo of what I want the code to be: gyazo.com/a00073f85ad4bd0373df0efd7d9de2a3.png Thanks for helping.. And sorry for not being descriptive enough.
There, Edited just for you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.