Forums

Auto Focus on the first field when the form is showed.

balrom 17 Apr, 2009
Hi,
i'm trying this wonderful extension, and have a little question.
I've created my own form and wold want to gain autofocus on the first field when the form is showed.
Is possible to do this?
Thanks in advance.
Regards.
Max_admin 20 Apr, 2009
Hi balrom,

you can use the domready event and do this, something like this :


<?php
$script = "
window.addEvent('domready', function() {
    $('field_id').focus;
    });
";
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration($script);
?>


in the form HTML box and replace field_id with the real field id!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
balrom 20 Apr, 2009
Thank you max, it works fine!!

I've made a little correction to your code, the javascript focus method must have the brackets ;-)
Regards.
Bart


<?php
$script = "
window.addEvent('domready', function() {
    $('field_id').focus();
    });
";
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration($script);
?>
Max_admin 20 Apr, 2009
Nice catch, thanks Bart! :wink:

Cheers,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.