Nasrul Hazim Bin Mohamad

jQuery: Get Non-empty Text Area Inputs

May
08

Simple solutions to get non-empty text area inputs. Let say you have a list or text area like the following:

<textarea name="remark[about_us] id="remark-about_us"></textarea>
<textarea name="remark[about_us2] id="remark-about_us2"></textarea>
<textarea name="remark[about_us3] id="remark-about_us3"></textarea>
<textarea name="remark[about_us4] id="remark-about_us4"></textarea>
<textarea name="remark[about_us5] id="remark-about_us5"></textarea>
var remarks = $('[name^=remark]');
$.each( remarks, function( index, value ){
	var remark = $.trim($('#'+value.id).val());
	if(remark.length != 0) { 
		console.log(value.id + ' - ' + value.value);
	} else {
		console.log(value.id + ' - empty');
	}
});

Here a sample I have on my current working project.

Get Non-Empty Text Area

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

20 − 18 =