Execute function if the input contains certain text

3
$(function() {
    if ($fa.ismod = true) {
        if (document.getElementById("input#message").value = "/msg") {
            alert('tudo okay');
        }
    }
});

This code should alert if the input # message contains the / msg text but it returns this:

  Uncaught TypeError: Can not set property 'value' of null (...)

    
asked by anonymous 18.11.2015 / 00:48

1 answer

4

The error displaying occurred because you tried to assign value to an element that does not exist.

This will validate the value of the HTML element that has id equal message .

if (document.getElementById("message").value === "/msg") {
    alert('tudo okay');
}

This will validate the input HTML element that has id equal to message .

if ($("input#message").val() === "/msg") {
    alert('tudo okay');
}

Note the errors I pointed out by comment.

    
18.11.2015 / 01:06