0

I need to do in Combobox exact things that I do with in textbox. When the page loads Combobox first value with like Focus().select()

$(document).ready(function(){
    $('#sel_bookID').focus().select();
});
<input type=text id="sel_bookID" value="ddddddddd" name='userid1'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>

Like this when page load

enter image description here

Darpan Patel
  • 387
  • 3
  • 15

3 Answers3

0

You can set an option as the default using the selected attribute:

<select>
  <option>Opt 1</option>
  <option selected="true">Opt 2</option>
  <option>Opt 3</option>
</select>

However, if you really want to use jQuery to do this you can use .prop method:

$(document).ready(function() {
  $('#opt2').prop('selected', true);
});
<select>
  <option>Opt 1</option>
  <option id="opt2">Opt 2</option>
  <option>Opt 3</option>
</select>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
Nick Parsons
  • 45,728
  • 6
  • 46
  • 64
0

Maybe your trying to do like this?

<select id="sel_bookID">
   <option value=""></option>
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
</select>


$(document).ready(function(){
    alert($("#sel_bookID option:selected").text());
});


or maybe you only need autofocus please check this link on select autofocus

j1rjacob
  • 411
  • 11
  • 27
0

    $(document).ready(function(){
        $('#sel_bookID').focus().select();
    });



        <select id="sel_bookID" name='userid1'>
            <option value="ddddddddd">ddddddddd</option>
        </select>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>


Ajinkya
  • 325
  • 3
  • 12