views:

144

answers:

3

When i executed this,

var a = trimAll(document.getElementById("txt_msg").value);

When i inspected through web developer toolbar I got the Error: trimAll is not defined..

Any suggestion...

A: 

Here's a trimAll function that might help:

http://www.jslab.dk/library/String.trimAll

+1  A: 

According to the latest edition of the ECMAScript spec, trimAll is not a standard Javascript function. Either it is a browser-specific extension, or a third-party library.

Exercise due caution if you want your Javascript / website to work in all browsers.

Stephen C
+1  A: 

As others have mentioned, the error is indicating that the trimAll() function has not been defined. As trimAll() is not a standard JavaScript function, you would need to write one named trimAll() in order to call it.

There are many ways to write a string trimming function. Some functions are compact, some are easy to read, others are blazing fast.

It's worth keeping in mind that native JavaScript trim is supported in ECMAScript 5. I suspect the intention of your trimAll() function call would be the same functionality as trim().

So, if you plan to write your own trim function, it might be worth while checking for the existence of a native trim and using that in preference to your own string trimming method if you prefer.

Dean Burge