You're probably asking to trim new lines / spaces from the beginning and end of a textarea:
$(this).val().replace(/^\s+|\s+$/g, '').length
Also, setting true/false on the disabled attribute will do nothing: replace them with prop.
سؤال
I'm disabling the submit button until something is entered. The problem is that the Enter Key is counting as a Character or "length".
This is for a TextArea
Count.js.coffee
$(document).ready ->
$(".cmnt_btn").attr "disabled", true
$(".cmnt_area").keyup ->
# Disable button when nothing is entered
# Enter Key tricks this
unless $(this).val().length is 0
$(".cmnt_btn").attr "disabled", false
else
$(".cmnt_btn").attr "disabled", true
# Character Count
left = 300 - $(this).val().length
left = 0 if left < 0
$(".cmnt_counter").text left
How can i "disable" the enter Key counting as a Character or disabling the key until something else is entered ?
المحلول
You're probably asking to trim new lines / spaces from the beginning and end of a textarea:
$(this).val().replace(/^\s+|\s+$/g, '').length
Also, setting true/false on the disabled attribute will do nothing: replace them with prop.