Yeah,
To echo Chris's last response, don't go re-inventing the ability to
attach multiple events to an object. Any major javascript framework
today provides multiple event handling. Prototype does this through
Event.observe, so instead of pushing functions into an array just call
Event.observe(document, 'load', function(){whatever;}); You can call
this multiple times, and it will chain the events magically for you.
If you want to get really cool, download lowpro:
http://www.danwebb.net/2007/4/16/low-pro-0-4-released
This gives you Event.onDomReady which doesn't wait for images to be loaded...
If you aren't using a javascript library, jordans method will work.
If you're using prototype, add the class 'focus' to the element you
want to be in focus, than either attach this function to the onload
event or just call it at the bottom of the document:
function focus() {
$$('input.focus').first().focus();
}
On 4/30/07, Jordan A. Fowler <[EMAIL PROTECTED]> wrote:
Oops, i made a mistake, check below:
On Apr 30, 2007, at 2:54 PM, Jordan A. Fowler wrote:
Glenn,
Something I like to do, to keep things clean is to setup a Javascript onLoad
Queue, which is an array of functions that should be run upon the page being
loaded.
In your application.js file, add:
var onLoadQueue = [];
Then, you can add application wide onload items to the queue or add
controller/action specific javascript files, within which you just add to
the queue as follows:
onLoadQueue.push(function () {
$('text_field_id').focus();
alert("i've been called!");
});
Add another file called onload.js to your javascripts directory and add this
code to it:
onLoadQueue.each(function (f) {f();});
document.onload = function () {onLoadQueue.each(function (f) {f();)});};
Let me know if you have any questions.
-Jordan
On Apr 30, 2007, at 2:48 PM, Glenn Little wrote:
I'm trying to set the initial focus to some specific form
field on a page.
I can use a prototype call to do something like:
<% form_tag .... %>
<%= text_field_tag ... %>
<script>$('text_field_id').focus();</script>
<%= some_other_field_tag... %>
and it works, but I'm just wondering if there was a cleaner
way that I'm missing. Ideally, I'd like not to have to
explicitly state the id of the input element. Have I missed out
on an :initialfocus => true option to the form field helpers
or anything like that?
Thanks...
-glenn
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby
--------------------------------------------------------------
Jordan A. Fowler
1830 Market St. #4
San Diego, CA 92102
E-mail: [EMAIL PROTECTED]
AIM: virtuosojordan
Phone: 406.546.8055
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby
--------------------------------------------------------------
Jordan A. Fowler
1830 Market St. #4
San Diego, CA 92102
E-mail: [EMAIL PROTECTED]
AIM: virtuosojordan
Phone: 406.546.8055
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby