"Onclick button focus"
Bootstrap 3.3.0 Snippet by daman

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <h2>On button click focus Text Field</h2> <form> <div class="form-group"> <input type="text" id="parent1" class="inputField" /> <button type="button" class="btn btn-primary triggerBtn">Focus me!</button> </div> <div class="form-group"> <input type="text" id="parent2" class="inputField"/> <button type="button" class="btn btn-primary triggerBtn">Focus me!</button> </div> <div class="form-group"> <input type="text" id="parent3" class="inputField" /> <button type="button" class="btn btn-primary triggerBtn">Focus me!</button> </div> <div class="form-group"> <button type="button" id="child1" class="btn btn-success">Enter 1</button> <button type="button" id="child2" class="btn btn-success">Enter 2</button> <button type="button" id="child3" class="btn btn-success">Enter 3</button> </div> </form> </div>
var curr; $(document).on("click",".triggerBtn", function() { var TextField = $(this).closest('div').find('.inputField'); if($(TextField).is(":visible")) { $(TextField).focus(); curr = TextField.attr('id'); } }); $(document).on("click","#child1",function(){ $('#'+curr).val("1"); }); $(document).on("click","#child2",function(){ $('#'+curr).val("2"); }); $(document).on("click","#child3",function(){ $('#'+curr).val("3"); });

Related: See More


Questions / Comments: