Add length of string into Error Message and also test for string trimmed


Please help , I am a java script dunce. (better on the server side)
I want to include the actual  string length in the error message for Notes in the code below.
Also in the example below how would I test for the length trimmed - then put up the error, in case the user has
copied in a lot of spaces. I strip these off on the server side. I tried various things and it did not

				var error = "";
				var headline = $("#headline").val();				
				var notes = $("#notes").val();
				if (!($.trim(headline).length)) {
					var error = error +'Please enter headline for your add<br>'
				if (!($.trim(notes).length)) {
					var error = error + 'Please enter your advertisement for housesitting<br>'
				if (notes.length >= 4000) {
					var error = error  + 'You have exceeded the 4,000 character limit,  Please edit your Text and try again.<br>'
				if (headline.length >= 120) {
					var error = error + 'Headline for housesitting must be bellow Max 120 Characters, Please edit your Text and try again.<br>'
					var UIAlertDialogApi = function () {			
						function handleAlerts() {				
								container: '#bootstrap_alerts_demo', // alerts parent container(by default placed after the page breadcrumbs)
								place: 'append', // append or prepent in container 
								type: 'danger',  // alert's type
								message: error,  // alert's message
								close: true, // make alert closable
								reset: true, // close all previouse alerts first
								focus: true, // auto scroll to the alert after shown
								closeInSeconds:0, // auto close after defined seconds
								icon:'warning' // put icon before the message
				} else{
				setTimeout(function() {
					window.location.href = window.location.href;
				}, 1000);

Open in new window

Ian WhiteOwner and FounderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In javascript you do not need to convert numbers to strings, it will let you concatenate strings with numbers:
if (notes.length >= 4000) {
					var error = error  + 'You have exceeded the 4,000 character limit, You have entered ' + notes.length + ' characters, Please edit your Text and try again.<br>'

Open in new window

I did not understand your second question

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ian WhiteOwner and FounderAuthor Commented:
HI Thanks that works for the message.

notes may include spaces before and after. The user could have copied the text in including leading and following spaces.  I remove these on the server side. However I didn't want to put an error up if the notes.length counted the leading and trailing spaces.  So I could either trim off the spaces - how to do using java script in the example below OR test for the string excluding spaces?
Just execute this as the first statement:

Open in new window

It will trim the value of the "notes" textbox
Ian WhiteOwner and FounderAuthor Commented:
Excellent Thanks for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.