Stryder
11-03-2009, 11:40 AM
So here I am, screwing with a HTML input field, I textbox to be precise.
I decide that I want the text cursor to appear in the box when the page loads, I know from my very swisscheesed memory it involves focus, so I start hunting around the internet.
Obviously there are many brief explanations people write, some go into great detail about the entire document/element structure, which is great and everything but it didn't answer the simple question of "how to do it".
The Input allows for an OnFocus event, so naturally some silly trivial bearing steered me to attempt to use it to focus a focus(); event in it, however I didn't take into consideration that "focusing in a focus event" was generating a recursion where the focus event would only be called when someone actually put the cursor there to type, Kind of making completely redundant.
So what was the real method to do it?
Well it required using the OnLoad event in the BODY. This is the event called when the actual page loads (Incidentally it's triggered when the page is fully loaded... well when the Body has finished loading anyway).
Obviously though I had to write the full identifier, this can be done using the long handed elementid etc, however my elements were named to make it a little easier. in my instance it was document.form1.input1.focus();
Anyhow, hopefully this note should help in the future of "remembering" things that I tend to forget.
I decide that I want the text cursor to appear in the box when the page loads, I know from my very swisscheesed memory it involves focus, so I start hunting around the internet.
Obviously there are many brief explanations people write, some go into great detail about the entire document/element structure, which is great and everything but it didn't answer the simple question of "how to do it".
The Input allows for an OnFocus event, so naturally some silly trivial bearing steered me to attempt to use it to focus a focus(); event in it, however I didn't take into consideration that "focusing in a focus event" was generating a recursion where the focus event would only be called when someone actually put the cursor there to type, Kind of making completely redundant.
So what was the real method to do it?
Well it required using the OnLoad event in the BODY. This is the event called when the actual page loads (Incidentally it's triggered when the page is fully loaded... well when the Body has finished loading anyway).
Obviously though I had to write the full identifier, this can be done using the long handed elementid etc, however my elements were named to make it a little easier. in my instance it was document.form1.input1.focus();
Anyhow, hopefully this note should help in the future of "remembering" things that I tend to forget.