html5 - Show remaining characters for a text box using javascript -
this question has answer here:
- javascript character count 3 answers
without editing html file, need show characters remaining maximum of 300 chars.
<form> <fieldset> <div class="formrow clearfix"> <span> <label for="comments">comments</label> <label for="comments" id="charsleft">(300)</label> </span> <textarea name="comments" id="comments" rows="4" cols="40"></textarea> </div> </fieldset> </form>
i have function ready im not sure on have in function work.
$(document).ready(function () { var text_max = 300; $('#charsleft').html(text_max); $('#textarea').keyup(function() { var text_length = $('#textarea').val().length; var text_remaining = text_max - text_length; $('#charsleft').html(text_remaining); }); });
i have searched internet , other solutions try resolve cant seem working. appreciated.
you this
var holder = document.getelementbyid("charsleft"); var commentsinput = document.getelementbyid("comments"); function updateremainingcharacters() { var charsleft = 300 - commentsinput.value.length; holder.innertext = "(" + charsleft + ")"; } commentsinput.addeventlistener('keyup', updateremainingcharacters); commentsinput.addeventlistener('paste', updateremainingcharacters);
Comments
Post a Comment