Forums

set focus on textbox

federici 24 May, 2012
Hi, i'm italian, sorry for my english 😀

i have a problem with a form built with ChronoForms, i should set the focus in the first textbox on my page, i used the Load JS in the On Load section and i inserted this script


document.getElementById('tablet_focus').focus();

where tablet_focus is the Field ID on the textbox

but it don't work

can you help me?
GreyHead 24 May, 2012
Hi federici,

What so you see in your browser web developer tools? Most likely the input isn't loaded when that code runs. Please try this version instead:
window.addEvent('domready', function() {
  $('tablet_focus').focus();
});

Bob
federici 24 May, 2012
great, it works perfect

thank you very much


Claudio
funza 14 Aug, 2013
Hi
I am trying to use the following code to set focus on a field but not working.

window.addEvent('domready', function() {
$('input_name').focus();
});

The Field ID is 'input_name'

The code is placed in Load Js element of On Load section.

Please help..

Thanks
GreyHead 14 Aug, 2013
Hi funza,

It needs to be the input ID, not the input name - though often they are the same.

Bob
funza 14 Aug, 2013
Hi Bob,

Thanks for the prompt reply.

I am new to this and am not sure by what you meant as input ID.

The properties of the textbox in the form is configured as follows:
Label Text = Name
Field Name = input_name
Field Max Length 100
Field Size 50
Field Title
Field ID = input_name
Field Class = validate['required','%valName'] -> have a validation

Thanks.
GreyHead 14 Aug, 2013
Hi funza,

This is the ID so it should be OK
Field ID = input_name


Do you see any errors in the JavaScript console? (Hit F12 in your browser to open the Web Developer tools).

Bob
This topic is locked and no more replies can be posted.