If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

When you put that code in the <head>, *NONE* of those elements that you are trying to get using document.getElementById() *EXIST* yet!!!

On top of that, you misunderstand the point of the

Code:

(
function lucas() { }
)();

outermost parentheses in that coding form. The first pair of parentheses *encapsulate* the function within them. The second pair then *INVOKE* the encapsulated function *IMMEDIATLY*. Your external call to lucas( ) is a waste of time and code; the call to that function has already been performed by the last ();

But in any case, this will never work, as given, if you inject it into the <head>, as is.

You have two choices: The better choice is to stop using C# code to inject the JavaScript. Instead, simply put it into your page *JUST BEFORE* the </body> tag. You can either simply drop it inline into your ".aspx" page or you can put it in separate ".js" file and then drop a reference to it (e.g., <script type="text/javscript" src="lucas.js"></script>) just before the </body>.

The not-as-good choice is to lose the parentheses shown in red and magenta above, completely.

And then, in place of your direct call to lucas( ), use window.onload = lucas;
That way, your function will not be called until the page is completely loaded and so all the elements you are using the ID's of will then exist.

CAUTION: If you have other JavaScript on the page, it might already be using window.onload and so you may then cause it to not work or perhaps it will override your use on onload. If that's the case, you will have to attach your lucas function as an event handler to the load, instead.

When you put that code in the <head>, *NONE* of those elements that you are trying to get using document.getElementById() *EXIST* yet!!!

On top of that, you misunderstand the point of the

Code:

(
function lucas() { }
)();

outermost parentheses in that coding form. The first pair of parentheses *encapsulate* the function within them. The second pair then *INVOKE* the encapsulated function *IMMEDIATLY*. Your external call to lucas( ) is a waste of time and code; the call to that function has already been performed by the last ();

But in any case, this will never work, as given, if you inject it into the <head>, as is.

You have two choices: The better choice is to stop using C# code to inject the JavaScript. Instead, simply put it into your page *JUST BEFORE* the </body> tag. You can either simply drop it inline into your ".aspx" page or you can put it in separate ".js" file and then drop a reference to it (e.g., <script type="text/javscript" src="lucas.js"></script>) just before the </body>.

The not-as-good choice is to lose the parentheses shown in red and magenta above, completely.

And then, in place of your direct call to lucas( ), use window.onload = lucas;
That way, your function will not be called until the page is completely loaded and so all the elements you are using the ID's of will then exist.

CAUTION: If you have other JavaScript on the page, it might already be using window.onload and so you may then cause it to not work or perhaps it will override your use on onload. If that's the case, you will have to attach your lucas function as an event handler to the load, instead.

The problem is that i need to use c# because it's a BHO ... i think that the problem is because of the whole website is made by frames ...Soo Javascripts will not work with frames ??? In other pages it's working ( like google , yhaoo ,etc ) but with websites with frames it doesn't work