How to focus on field?

Hello,

I’m looking for a dhtmlxForm method that will put the focus on a form field.

I had tried

myForm.setItemFocus("myFieldName");

and several variations of it, but I get a JavaScript error saying the object doesn’t support the method.

Thank you.

Hello, DHTMLX. The courtesy of your reply would be greatly appreciated. Thank you.

Hi,

Have you tried using the DOM?, I mean something like this:
.
.
.
var formData =
[{type: “input”, name: “usrLogin”, value:"", label:“User:”},
{type: “password”, name: “usrPasswd”, value: “”, label: “Password:”},
{type: “label”, name: “statLogin”,label: “STATUS:”},
{type: “button”, name: “btnLogin”, value: “Login”, command: “sendServer”},
];

var objForm = loginWindow.attachForm(formData);

document.getElementsByName(“usrLogin”).item(0).focus();
objForm.attachEvent(“onButtonClick”, function (name, cmd)
.
.
.
and you’re done. Hope it helps

Hello,

Please specify form version?

document.getElementsByTagName('input')[0].focus(); or window.setTimeout(function(){ document.getElementsByTagName('input')[0].focus(); }, 500);

myForm.setItemFocus(“myItem”);

have to wait to load the XML.

not found:

form.setItemFocus('name');

found:

window.setTimeout(function(){
      form.setItemFocus('name');
}, 500);

:slight_smile:

I see
In this way you need the next:

myForm.loadStruct("xml/form.xml", function(){ form.setItemFocus('name') });

Darya++
Thanks :slight_smile:

You are welcome!