1

I am trying to execute this but cant see any result:

<script> function init() { document.getElementById('welcome').innerHTML = "<font color=white>Logged As:"+ param + "</font>"; } window.onload = init; </script> <body> ........... <div class="span-24 bottom_header" id="welcome"></div> ........... </body> 

what is wrong here..........

3
  • What browser? is window.onload being called? Try putting an alert('hi') in your init() ? Commented May 2, 2009 at 11:36
  • 1
    Where is the param variable defined? Commented May 2, 2009 at 11:39
  • 4
    The only reason this doesn't work is because param is undefined. (Like Perspx suggested). No idea why you've accepted the answer you have below - doesn't solve your problem... Commented May 2, 2009 at 12:56

6 Answers 6

8

Maybe because your background is white and you are setting white color to your font: <font color=white>. Try with black :-)

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

Comments

5

This self-contained example works perfectly for me in Firefox and IE7:

<html><head><script> function init() { document.getElementById('welcome').innerHTML = "<font color=white>Logged As: TEST</font>"; } window.onload = init; </script></head> <body> <div class="span-24 bottom_header" id="welcome"></div> </body></html> 

You are adding white-on-white text, remember...

1 Comment

In your code you removed param therefore it worked. As JimmyP said the problem is because param is undefined.
3

Two things:

1) Make sure you don't have more than one element on the page with the ID "welcome"

2) Off topic, but revise your need to use the "font" tag. It's heinously deprecated at this point in time. You should be using <span style="color:white;">Logged as: TEST</span>

Comments

3

Perspx and JimmyP already mentioned this in the Question's comments:

Are you sure you the param variable exists somewhere before executing your function?

Comments

3

Have you considered using a framework such as jquery? The above code would then become...

$('#welcome').html("<font color='white'>Logged As: TEST</font>"); 

13 Comments

Pretty harsh downvote, the example code is almost always a snippet.
You marked me down for such a suggestion? I'm assuming that isn't the only thing he will be wanting to do with JS so I was simply making a suggestion he uses a framework to simplify things.
All I'm saying is using jQuery won't solve his problem...and will most probably even create more problems for him
OK fair enough. I am of the opinion that a framework is designed to make things easier not the other way round. I'm beginning to realise that offering alternative suggestions is something that is frowned upon on here.
Not only is jQuery not required for this simple task but the code posted won't work. I think you meant $('.welcome').text('...');
|
3

Actually, the correct jQuery translation would be:

$('#welcome').html("<font color='white'>Logged As: TEST</font>"); 

Three cheers for my lack of "reputation"!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.