11/14 System throws an error


#1

Hi to All! My code is correct i guess but the system throws an error ((Oops, try again. Did you put '#button' inside your $().click() ?)). Have somebody experienced similar issue? If so, please let me know what to do!


#2

Judging by the error you should have $('#button').click(). I can't see your code so I can't offer any advices, how can you be certain it's correct?


#4

My code is following

$(document).ready(function () {

var input = $('input[name=checkListItem]').val();

$('#button').click(function(){
    
    var toAdd = input;
    
    });

});

#5

Here is my code (it works).

$(document).ready(function(){
    $("#button").click(function(){
        var toAdd = $('input[name=checkListItem]').val();
    })
})

It's practically the same, but try with my code because you will assign value to input at the time document is loaded. at that time document is empty and then assign that value to toAdd. I will assign my value to toAdd only when the button is clicked. I believe this will resolve your problem.


#6

Thanks it works!!! I don't know what was wrong maybe semicolons in my code?


#7

I'm not 100% sure, but as I said, you assigned the $('input[name=checkListItem]').val(); to some variable called input. And you did it immediately after document becomes ready, and at that point, input item is empty. So I think you was adding and empty value to your toAdd variable and that caused the code to fail at evaluation.


#8

Ok thanks for explanation!!!