Jump to content

write single line on page


Kaoru

Recommended Posts

I've just finished working on my "members only" section - I know, JavaScript isn't the best thing to use for security, but it's all I know how to use.I'm using a cookie to store the username supplied when the password is entered correctly, when the user views the main page on the secured section of the site, it brings up an alert with a welcome message.Instead of using an alert, I want the function to write a welcome message on the page itself without replacing any text already on that page:

<HEADING><Welcome message><Other text>
Above show how I want it to look, below shows the function that checks for the cookie's existance and supplies the welcome message:
function checkCookie() { username=getCookie('username') if (username!=null) { alert('Welcome again '+username+'!') } else { username=prompt('Please enter your name:',"") if (username!=null && username!="") { setCookie('username',username,365) } }}
Link to comment
Share on other sites

Create an empty div where you are going to display the welcome message

<div id='welcomemsg'></div>

than in javascript function replace the alert with:

document.getElementById("welcomemsg").innerHTML="Welcome message";

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...