I am making a website that will keep online records of the users gaming data. But my problem comes in here:

The user can create an account, if they dont have one, or login to an existing one.

 <a href="login.aspx">Login</a>&nbsp;&nbsp;&nbsp;<a href="" id="loginstate"></a>

Now my link tag with the id "loginstate" value will either be "Create Account" if the there arnt any cookies for the website on the users computer. Or it will be "Log out" if the user is logged in. That information I can change, by using this javascript code:

function changeLoginMenuText()
{
    if (isLogedIn == false)
    {
        document.getElementById("loginstate").innerHTML = "Create Account";
    }
    else if (isLogedIn == false)
    {
        document.getElementById("loginstate").innerHTML = "Logout";
    }
}

But now the href="" data should also change, so how do I change that data?

Recommended Answers

All 3 Replies

I guess you could use document.getElementById('loginstate').setAttribute('href', 'url');?

So yes, minitauros is correct. you can use that approach. Your code would look something like this..

function changeLoginMenuText()
{
    if (isLogedIn == false)
    {
        document.getElementById("loginstate").innerHTML = "Create Account";
        document.getElementById('loginstate').setAttribute('href', 'login.html');
    }
    else if (isLogedIn == false)
    {
        document.getElementById("loginstate").innerHTML = "Logout";
        document.getElementById('loginstate').setAttribute('href', 'logout.html');
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.