New to Kendo UI for jQuery? Download free 30-day trial

Focus the NumericTextBox on Label Click

Environment

Product Progress Kendo UI NumericTextBox for jQuery
Operating System Windows 10 64bit
Visual Studio version Visual Studio 2017
Preferred Language JavaScript

Description

How can I focus the Kendo UI for jQuery NumericTextBox when the label element is clicked?

Solution

The following example demonstrates how to achieve the desired scenario.

<label for="numerictextbox">Number: </label>
<input id="numerictextbox" />
<script>
  $(function() {
    $("#numerictextbox").kendoNumericTextBox();

    //global click handler for all label elements
    $("label").click(function(e) {
       var label = $(this);
       var id = label.attr("for");
       var widget;

       if (id) {
           widget = kendo.widgetInstance($("#" + id), kendo.ui);

           if (widget) {
               e.preventDefault();
               widget.focus();
           }
       }
    });
  });
</script>

See Also

In this article