this is a code that enables the submit button if there are more than 100 chars in the textarea. However I can't get it work. Maybe the jquery version is wrong? I don't know.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<form>
<textarea id="textareaId"></textarea>
<input type="submit" id="submitId" disabled="disabled" />
</form>
<script type="text/javascript">
setInterval(function () {
if(("#textareaId").val().length > 100) {
$("#submitId").removeAttr("disabled");
} else {
$("#submitId").attr("disabled", "disabled");
}
}, 500); //Runs every 0.5s
</script>
You're missing a $
in front of ("#textareaId")
you are missing the $
by ("#textareaId")
and try using an onchange
instead of a setInterval
this might be more efficient:
$("#textareaId").change(function () {
if((this.value).length > 100) {
$("#submitId").removeAttr("disabled");
} else {
$("#submitId").attr("disabled", "disabled");
}
}).keyup(function(){$(this).change()});
fiddle: http://jsfiddle.net/maniator/7Kch9/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With