Select / highlight text on focus
Q:
Is there a way to select (highlight) the text from the input field when focusing the ComboBox?
A:
You can use the "OnOpen" client-side event of the ComboBox to do this. First, set up an event handler for this event:
<obout:ComboBox ... > <ClientSideEvents OnOpen="ComboBox1_Open" /> </obout:ComboBox>
Then, declare these two JavaScript functions:
<script type="text/javascript"> var textBox = null; function ComboBox1_Open(sender) { var txt = getTextBox(sender); txt.select(); }
function getTextBox(sender) { if (textBox == null) { var controls = document.getElementsByTagName('INPUT'); for (var i = 0; i < controls.length; i++) { if (controls[i].type == 'text' && controls[i].id.indexOf(sender.ID + 'TB') != -1) { textBox = controls[i]; } } }
return textBox; } </script>
|