activate() giving me trouble

0 views
Skip to first unread message

BDMovies1

unread,
Aug 14, 2008, 2:59:07 PM8/14/08
to Prototype & script.aculo.us
I've got a div that slides down when user clicks "Add Employee". That
div contains a form. I want the first name text box to have focus when
it slides down.

I have tried everything I know how, I've read over the API several
times...

This works...

<a href='#" onclick=" $
('add_employee_form').first_name_form.activate();">Give Focus</a>

However, this does NOT...

document.observe('dom:loaded', function() {
$('addEmpButton').observe('click', function(){
showModal('add');
$('add_employee_form').first_name_form.activate();
})
$('closeAddButton').observe('click', hideModal.curry('add'));
});

nor does this...

function showModal(elementID, event) {
Effect.Fade(elementID, {from:"0", to:"1", duration:".1"});
Effect.SlideDown(elementID, {duration: 0.5});
$('background').style.display = 'block';
$('add_employee_form').first_name_form.activate()
document.observe('keypress', keyListener);
}

This is really bugging me, b/c I know it is something simple....

Diodeus

unread,
Aug 14, 2008, 3:08:56 PM8/14/08
to Prototype & script.aculo.us
Do you have a function called activate()? or do you mean .focus()?

BDMovies1

unread,
Aug 14, 2008, 3:25:24 PM8/14/08
to Prototype & script.aculo.us
I don't have an activate() function, that's already in the API, and
I've tried .focus() as well.....

http://prototypejs.org/api/form/element/activate

Diodeus

unread,
Aug 14, 2008, 3:48:17 PM8/14/08
to Prototype & script.aculo.us
Perhaps the sliding is the problem. You may want to try setting the
focus as part of the afterFinish.

seesle

unread,
Aug 14, 2008, 3:06:14 PM8/14/08
to Prototype & script.aculo.us
Hi!

Im also really new to JS and also to Prototype but did you tryto give
the input type (the text box) an ID and make the activate() as
followed:

<script type="text/javascript">
Event.observe( window, "load", makeFocus );
function makeFocus()
{
$('name').activate();
}
</script>
<form>
<input type="text" id="name"/>
</form>

you can surely do this in your showModal Function or somewhere else!

Best Regards from Tyrol

seesle!

BDMovies1

unread,
Aug 15, 2008, 1:16:25 PM8/15/08
to Prototype & script.aculo.us
Ok, this is what I ended up doing and it worked fine

afterFinish: function(){ $
('add_employee_form').first_name_form.activate() };

I hadn't tried the window load event observer, but I did try with no
avail:

<body onLoad"document.add_employee_form.form_first_name.focus()">

Which worked if the form was shown from the start. So I think it was
the Slide that was the problem.
Reply all
Reply to author
Forward
0 new messages