I know how to display an error message if the user leaves a required input field blank when filling in a form, but I am not able to do the same with the textarea.
views:
38answers:
1
+1
A:
i think on change fires for text areas as well so assuming it does
theTextArea.onChange = function(){
if(this.value == ''){
alert('You must supply a value for this field');
}
};
or with jquery
$(document).ready(
function(){
$('#mytextarea').change(function(){
var $this = $(this);
if($this.val() == ''){
alert('You must supply a value for this '+$("label[for='mytextarea']").text());
}
});
});
prodigitalson
2010-02-06 00:22:05
I would change this.value == '' to /^\s*$/.test(this.value) so it matches whenever there's only whitespace.
Matthew Flaschen
2010-02-06 00:30:25