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?

Re: How to change the value of a link with javascript? 80 80

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

Re: How to change the value of a link with javascript? 80 80

Thanks I will give that a try.

Re: How to change the value of a link with javascript? 80 80

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 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.