1

Ok, I've been fiddling with this for almost 40 minutes now... WTF am I doing wrong?

http://jsfiddle.net/aMhjJ/

 <input type="Checkbox" name="E1019" id="E1019" value="1">
 <div id="result"></div>

Javascript:

$('#E1019').change(function () {

    if ($('E1019').is(':checked')) {
            $('#result').html('checked');
        } else {
            $('#result').html('unchecked');
        }
});

Problem solved: Missing # in if statement: $('E1019') should be $('#E1019')

Wes
  • 301
  • 4
  • 13

1 Answers1

6

You have used element selector instead of id selector - missing # in front of E109

if ($('#E1019').is(':checked')) {

Demo: Fiddle


But you can also use the checked property of the dom element

$('#E1019').change(function () {
    if (this.checked) {
        $('#result').html('checked');
    } else {
        $('#result').html('unchecked');
    }
});

Demo: Fiddle

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
  • 1
    +1. What is your daily reputation max? 200? after that you can give as chnace to earn some reputation. And can you look [here](http://stackoverflow.com/questions/20985465/javascript-advantages-and-disadvantages-of-dynamically-on-fly-creating-style) – Khamidulla Jan 10 '14 at 00:54
  • @Phoenix I'll give a try... probably in the evening – Arun P Johny Jan 10 '14 at 00:56
  • OMG - I knew it was something staring me right in the face, needed another set of eyes. Thanks – Wes Jan 10 '14 at 00:57
  • @Phoenix sure... let me know once you are done editing the question – Arun P Johny Jan 10 '14 at 00:58
  • Ok. I will post here or somewhere else in your questions as comment – Khamidulla Jan 10 '14 at 00:59