Hi, I am able to set focus to a particular textbox onload of a form u

Hi,

I am able to set focus to a particular textbox onload of a form using the below code :
document.getElementById("textControl_fd_component_"+window.FormDesigner.runtimeNamespace+"requestComments").focus();

But this doesn't work for textarea. The page throws an error at run-time. Is it because of "textControl_fd_component"? What do I replace that with?...

OriginalPostID-99124

OriginalPostID-99124

  Discussion posts and replies are publicly visible

Parents
  • That worked for me even with 30 components but it could be that you are facing a race conditions (the components are not available yet when the code is executed).

    My suggestion would be:

    1. Switch to this other syntax

    $("#plainTextControl_fd_component_" + window.FormDesigner.runtimeNamespace + id).get(0).focus();

    2. This means your line will now be

    $("#plainTextControl_fd_component_" + window.FormDesigner.runtimeNamespace + "requestComments").get(0).focus();


    3. If the issue persists wrap it in a setTimeout to delay its execution. This example dealys it for 50ms

    setTimeout(function() {$("#plainTextControl_fd_component_" + window.FormDesigner.runtimeNamespace + "requestComments").get(0).focus();}, 50);



Reply
  • That worked for me even with 30 components but it could be that you are facing a race conditions (the components are not available yet when the code is executed).

    My suggestion would be:

    1. Switch to this other syntax

    $("#plainTextControl_fd_component_" + window.FormDesigner.runtimeNamespace + id).get(0).focus();

    2. This means your line will now be

    $("#plainTextControl_fd_component_" + window.FormDesigner.runtimeNamespace + "requestComments").get(0).focus();


    3. If the issue persists wrap it in a setTimeout to delay its execution. This example dealys it for 50ms

    setTimeout(function() {$("#plainTextControl_fd_component_" + window.FormDesigner.runtimeNamespace + "requestComments").get(0).focus();}, 50);



Children
No Data