This is a migrated thread and some comments may be shown as answers.

Focus in Input text IE 8

4 Answers 88 Views
Editor
This is a migrated thread and some comments may be shown as answers.
dali
Top achievements
Rank 1
dali asked on 27 Dec 2010, 03:26 PM
Hi,
I have a web form with RadEditor and input text,I want to put the cursor in the text input, so i use this code from http://www.telerik.com/help/aspnet-ajax/editor_setfocus.html
<body onload="SetFocusOnTextBox();">
   <form id="form1" runat="server">
   <asp:ScriptManager id="ScriptManager" runat="server"/>                             
   <telerik:radeditor runat="server" ID="RadEditor1">
       <Content>
           Here is sample content!
       </Content>
   </telerik:radeditor>
   <input type="text" id="text"/>
   <input type="button" value="Set Focus On RadEditor" onclick="SetFocusOnRadEditor()" />
   <script type="text/javascript">
   function SetFocusOnRadEditor()
   {
       var editor = $find("<%=RadEditor1.ClientID%>"); //get a reference to RadEditor client object
       editor.setFocus(); //set the focus on the the editor
   }
   function SetFocusOnTextBox()
   {
       var editor = $get("text"); //get a reference to the input textbox with id text
       editor.focus(); //set the focus on the the textbox
   }
   </script>
   </form>
</body>

It's OK with Forefox or chrome , but not work with IE 8

4 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 28 Dec 2010, 12:33 PM
Hi Dali,

The following code works fine on my end in IE8 and Firefox:

<telerik:radeditor runat="server" ID="RadEditor1">
    <Content>
        Here is sample content!
    </Content>
</telerik:radeditor>
<br />
<input type="button" value="Set Focus On RadEditor" onclick="SetFocusOnRadEditor()" />
<br /><br />
<input type="text" id="text"/>
<br />
<input type="button" value="Set Focus On TextBox" onclick="SetFocusOnTextBox()" />
    
    
<script type="text/javascript">
function SetFocusOnRadEditor() {
    var editor = $find("<%=RadEditor1.ClientID%>"); //get a reference to RadEditor client object
    editor.setFocus(); //set the focus on the the editor
}
function SetFocusOnTextBox() {
    var editor = $get("text"); //get a reference to the input textbox with id text
    editor.focus(); //set the focus on the the textbox
}
</script>

You can see my test in the following video: http://screencast.com/t/eu8WjyJe.

Best wishes,
Rumen
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
dali
Top achievements
Rank 1
answered on 28 Dec 2010, 04:18 PM
OK, it's work but my problem is to focus the cursor on the page load,
<body onload="SetFocusOnTextBox();">
    <form id="form1" runat="server">
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server">
    </telerik:RadStyleSheetManager>
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <div>
        <telerik:RadEditor runat="server" ID="RadEditor1">
            <Content>
        Here is sample content!
            </Content>
        </telerik:RadEditor>
        <br />
        <input type="button" value="Set Focus On RadEditor" onclick="SetFocusOnRadEditor()" />
        <br />
        <br />
        <input type="text" id="text" />
        <br />
        <input type="button" value="Set Focus On TextBox" onclick="SetFocusOnTextBox()" />
        <script type="text/javascript">
            function SetFocusOnRadEditor() {
                var editor = $find("<%=RadEditor1.ClientID%>"); //get a reference to RadEditor client object
                editor.setFocus(); //set the focus on the the editor
            }
            function SetFocusOnTextBox() {
                var editor = $get("text"); //get a reference to the input textbox with id text
                editor.focus(); //set the focus on the the textbox
            }
        </script>
    </div>
    <telerik:RadAjaxManager runat="server">
    </telerik:RadAjaxManager>
    </form>
</body>

But it does't work
0
Rumen
Telerik team
answered on 29 Dec 2010, 10:40 AM
Hi Dali,

My recommendation is to set the focus after a small delay of time, e.g.

function SetFocusOnTextBox() {
    setTimeout(function () {
        var editor = $get("text");
        editor.focus(); //set the focus on the the textbox
    }, 1000);
}



Regards,
Rumen
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
dali
Top achievements
Rank 1
answered on 29 Dec 2010, 11:15 AM
1000% works ,
thanks
Tags
Editor
Asked by
dali
Top achievements
Rank 1
Answers by
Rumen
Telerik team
dali
Top achievements
Rank 1
Share this question
or