tags:

views:

261

answers:

6

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  A: 

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

$('#welcome').html("<font color='white'>Logged As: TEST</font>");
Ian Roke
...using a framework for such a simple task? no, no...
Andreas Grech
Pretty harsh downvote, the example code is almost always a snippet.
Chad Grant
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.
Ian Roke
All I'm saying is using jQuery won't solve his problem...and will most probably even create more problems for him
Andreas Grech
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.
Ian Roke
2 points of rep down and you call it harsh? It may be a bit unfair but harsh? I personally don't like jQuery answers to simple JavaScript questions but if the answer is valid then it isn't wrong.
Peter Perháč
The code he posted is valid, so doing it the same way but with jQuery isn't sufficient of an answer that should supposedly fix his issue.
Andreas Grech
I love jQuery but I agree that there is no reason to invoke it when the actual non-jquery solution is just as simple.
brianpeiris
I think the reason why I got 2 down votes is because I didn't answer the question which asked why the code wasn't working therefore by default my answer is off topic.
Ian Roke
Not only is jQuery not required for this simple task but the code posted won't work. I think you meant $('.welcome').text('...');
J-P
yup, JimmyP is right; jQuery's text is a function not a property, thus Ian Roke's posted code is not correct. It should be more along the lines of $('.welcome').html('...'); since the OP wants to inject html
Andreas Grech
You are indeed both correct. I know this and use it in this way I need to double check things before I reply in future! :-)
Ian Roke
I'm correcting my code to avoid confusion from others finding this after a search but my initial point was still that using a framework might be easier and simpler than raw JS.
Ian Roke
It's OK, I gave you +. JQuery is nice.
Travis
+8  A: 

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

Darin Dimitrov
+5  A: 

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

RichieHindle
In your code you removed `param` therefore it worked. As JimmyP said the problem is because `param` is undefined.
Drahcir
+3  A: 

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>

Nathan Ridley
+3  A: 

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

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

Andreas Grech
+3  A: 

Actually, the correct jQuery translation would be:

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

Three cheers for my lack of "reputation"!

ken
haha you're actually right mate. hip hip hooray ;-) !
Andreas Grech
Should I delete this now?
ken