-1

I am chaging the text of a textbox, and its upating a label, but its hiding the checkbox? Can any one tell me what am I doing wrong?

Here

http://jsfiddle.net/6mZbm/6/

Here

<input type="text" id="txtInput" width="80px" />
</br>
<label id="lbl" />
</br>
</br>
<input type="checkbox" id="chkUpdate" />

The jQuery

$(document).ready(function(event) {

    $('#txtInput').keydown(function(event) {

        $('#lbl').text($('#txtInput').val());
        $('#lbl').change();
    });


    $('#lbl').change(function(event) {
        // alert($('#chkUpdate').size());
        $('#chkUpdate').change();
    });


});

Okay, I closed the label tag it's still not working... Check the updated fiddle.

EDIT 2 Okay its working now, but I am not getting what I wanna do, as should be clear from the code, I want to check uncheck (basically change) the checkbox, when the label is updated, but as you can see in the fiddle(s) (mine and the one Muthu Kumaran provided) the checkbox is not changing its state?

EDIT 3 : This seems to work with click() instead of change(), but as per jQuery specification, shouldn't it work with change too??

Kevin Montrose
  • 22,191
  • 9
  • 88
  • 137
Razort4x
  • 3,296
  • 10
  • 50
  • 88

3 Answers3

4

Because you didn't close the <label> tag,

Close the label tag and it work properly

<label id="lbl"></label>

Update: Working Demo: http://jsfiddle.net/6mZbm/8/

Muthu Kumaran
  • 17,682
  • 5
  • 47
  • 70
  • so, we can't close label like this? ` />` The way I closed checkbox and input? – Razort4x Oct 19 '12 at 09:46
  • you can use / to close single tags for eg. or but you needn't do - else use - – F. Müller Oct 19 '12 at 09:46
0

You are replacing the text of your <label> which includes your checkbox, get your checkbox out of label tag.

nix
  • 3,262
  • 2
  • 21
  • 36
0

just put

<label id="lbl"></label>
Bunjerd Sparrow
  • 88
  • 1
  • 10