Lonely
Lonely

Reputation: 613

Select textbox after clicking it in a checkbox type

I am using twitter bootstrap . I want to focus textbox in two ways:

  1. clicking the correspondent checkbox or
  2. clicking the textbox

these two cases are not working.

See this fiddle.

CSS: bootstrap-3.0.0

HTML:

<div class='container'>
    <div class="checkbox">
        <label>
            <input type="checkbox" value="" />option1
        </label>
    </div>
    <div class='checkbox'>
        <label>
            <input type="checkbox" value="" />
            <form role="form">
                <div class="row">
                    <div class="col-xs-2">
                        <input type="text" class="form-control" placeholder="Specify" />
                    </div>
                </div>
            </form>
        </label>
    </div>
</div>

Upvotes: 0

Views: 715

Answers (1)

Saravanan
Saravanan

Reputation: 1889

IF you can add jquery here it is:

$(document).ready(function(){
    $("#check_1").on("change",function(){
        if($(this).is(":checked"))
        {
            $("#text_1").focus();
        }
    });
});

And your HTML: (added id attribute)

<div class='container'>
<div class="checkbox">
    <label>
        <input type="checkbox" value="" />option1
    </label>
</div>
<div class='checkbox'>
    <label>
        <input type="checkbox" value="" id="check_1" />
        <form role="form">
            <div class="row">
                <div class="col-xs-2">
                    <input type="text" class="form-control" placeholder="Specify" id="text_1" />
                </div>
            </div>
        </form>
    </label>
</div>
</div>

Updated Fiddle: http://jsfiddle.net/Wr6tH/13/

Upvotes: 2

Related Questions