0

I have a bootstrap combobox defined and it is working fine except - I tried to get it to select all the text in the preselected option when the control gets focus. None of the events seem to be firing.

I have tried to use jquery $("#lookup").on("focus",function() {...}); will not fire. I have tried putting onclick="" and onfocus="" in the tag itself, neither fire.

Items to add:<br />
<select class="combobox input-small form-control"  name="normal" id="lookup">
    <option value="0" selected="selected" >type...</option>
    @{
    foreach (var item in Model.MyFoodsDropDown)
        {
        <option value="@item.NDB_No">@item.Shrt_Desc</option>
        }
    }
</select>

When I click on the combobox it places my cursor at the end of "type..." and I have to do a ctrl-a or use the mouse to select all before typing. It would be really cool for it to select all on focus.

  • How can you tell it did not fire? Did you try to put some console.log('focus fired'); or have you tried debugger keyword? and what is body of the function? This way we can make sure that you are selecting all text correctly. – Ashi May 31 '19 at 13:25
  • Also checkout this question, your question might be a duplicate, https://stackoverflow.com/questions/3150275/jquery-input-select-all-on-focus – Ashi May 31 '19 at 13:26
  • I put break points in the debugger and it never fired. I will look at the other question in the hope it has an answer. Thank you. – Jim Smith May 31 '19 at 13:35
  • $(".combobox").click(function () {$(this).select();}); Worked!!! Sweet! - Got this from the other question. – Jim Smith May 31 '19 at 13:40
  • Possible duplicate of [jquery input select all on focus](https://stackoverflow.com/questions/3150275/jquery-input-select-all-on-focus) – Ashi May 31 '19 at 14:16

0 Answers0