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

Set Focus to control under the tabstrip

3 Answers 354 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sravan Kumar Uddarraju
Top achievements
Rank 1
Sravan Kumar Uddarraju asked on 23 Jun 2008, 06:32 PM

Hi,

I have TabStrip with three tabs. When users click on the submit button, I have java script, it will validate all the controls of each tab with in the tabstrip. If anyone of the control does not enter the value my java scrip will popup the alert message.

What I am looking here is, after the pop-up this message it should set the focus to that particular control. I have all RadtextBoxes and Radcombo boxes with in the tabs. Please send me the javascript snippet which should set focus to control (RadTextBox or Radcombo) under the specific tab

Thanks,
Sravan

3 Answers, 1 is accepted

Sort by
0
Kevin Babcock
Top achievements
Rank 1
answered on 25 Jun 2008, 07:03 PM
Hi Sravan,

If you know the ID of the RadTextBox you are wanting to set the focus on, you can try this:

<telerik:RadCodeBlock runat="server" ID="RadCodeBlock1"
    <script type="text/javascript"
        function SetFocus() { 
            var textBox = $find("<%= RadTextBox1.ClientID %>"); 
            textBox.focus(); 
        } 
    </script> 
</telerik:RadCodeBlock> 

Alternatively, you can pass the ID in as an argument.

<telerik:RadCodeBlock runat="server" ID="RadCodeBlock1"
    <script type="text/javascript">      
        function SetFocusByID(id) { 
            var textBox= $find(id); 
            textBox.focus(); 
        } 
    </script> 
</telerik:RadCodeBlock> 

I hope this was helpful. If you still have questions, please let me know.

Sincerely,
Kevin Babcock
0
Sravan Kumar Uddarraju
Top achievements
Rank 1
answered on 25 Jun 2008, 10:14 PM
Hi,

Thanks for the replay

I tried the way which you explained. But no luck. The following code worked for me to focus on the RadTextBox or RadCombobox.

RadComboBox:
document.getElementById('<%=RadTextBox1.ClientID %>'  +

'_input').focus();

RadTextBox:
document.getElementById('<%=RadComboBox1.ClientID %>'  + '_text').focus();

Thanks,
Sravan

0
Kevin Babcock
Top achievements
Rank 1
answered on 26 Jun 2008, 02:11 AM
Hello Sravan,

First, I just want to point out that you can save some keystrokes by calling the $get(id) shortcut method instead of the document.getElementByID(id) method. If you'd like to read more about it, take a look here.

As for why your functions aren't working, I suspect it is because you are searching for the controls by appending the '_text' and '_input' strings to the ids. The method returns null because those ids don't exist. When you use '<%= RadTextBox1.GetClientID %>' it causes the server to render out the id it gives each control when the markup and script are sent to the client. Try it again without appending those strings and let me know how it goes.

Regards,
Kevin Babcock
Tags
General Discussions
Asked by
Sravan Kumar Uddarraju
Top achievements
Rank 1
Answers by
Kevin Babcock
Top achievements
Rank 1
Sravan Kumar Uddarraju
Top achievements
Rank 1
Share this question
or