javascript - Enable submit button only when there are characters in textarea -
javascript - Enable submit button only when there are characters in textarea -
i'm working on basic form has 1 textarea , 1 submit button:
<form action="admin-post.php" method="post"> <textarea style="width:630px;" aria-hidden="true" class="wp-editor-area" rows="6" autocomplete="off" cols="71" name="author_message" id="author_message"></textarea> <p class="submit"> <input type="submit" value="post message" class="button button-primary" id="submit" name="submit"> </p> </form> i want submit button enabled if there text entered within textarea. how can using javascript?
note cannot alter the value or html code of submit button.
if need continuous verification solve (without changing button attributes):
<textarea style="width:630px;" aria-hidden="true" class="wp-editor-area" rows="6" autocomplete="off" cols="71" name="author_message" id="author_message" onkeyup="if(this.textlength != 0) {submit.disabled = false} else {submit.disabled = true}"></textarea> and modify body tag:
<body onload="submit.disabled = true"> cheers
jsfiddle
edit:
if cannot modify body tag, add together disabled attribute button.
javascript html forms textarea
Comments
Post a Comment