I want to make sure that the input has value before submit but when I use "" or 'null', it, null will not disable it and "" will keep it disabled no matter what. Here is my code:
var prevScrollpos = window.pageYOffset;
$(window).scroll(function() {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
$("#container").fadeIn();
} else {
$("#container").fadeOut();
}
prevScrollpos = currentScrollPos;
});
if (document.getElementById("m").value === null) {
document.getElementById("send").disabled = true;
} else if (document.getElementById("m").value !== null) {
document.getElementById("send").disabled = false;
} else {
$(function() {
var socket = io();
$('form').submit(function() {
socket.emit('chat message', $('#m').val());
$("#m").val("");
return false;
});
socket.on('chat message', function(msg) {
$('#messages').append($('<li>').text(msg));
});
});
}
<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<div id="msgs">
<ul id="messages"></ul>
</div>
<form action="">
<div id="container">
<input id="m" autocomplete="off" /><button id="send">Send</button>
</div>
</form>
thanks!