Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to trim all the elements in the form using javascript

I need to trim all the trailing white spaces from the text elements of the form. I need to do it in minimal number of steps. As soon as i press onsubmit, it should trim all the white spaces and then perform the further operations. Is there any script available? If not then can you please help me to achieve my Goal. Currently i need to manual identify each element and then perform a trim like.

var username = myform.elements['username'].value;
username.trim();

How to generalize it?

like image 225
coderslay Avatar asked Jun 18 '12 09:06

coderslay


People also ask

How to trim input value in JavaScript?

trim() method is used to remove the white spaces from both the ends of the given string. Return value: This method returns a new string, without any of the leading or the trailing white spaces. In this example the trim() method removes all the leading and the trailing spaces in the string str.

How do I trim in node JS?

The trim() function is a string function of Node. js which is used to remove white spaces from the string. Parameter: This function does not accepts any parameter. Return Value: The function returns the string without white spaces.

How do you trim input value?

There are numerous ways to trim an input value. But for the sake of simplicity, we will use trim() method. The trim() method removes any extra space at the beginning and at the end of a string.

What does jquery TRIM () do?

trim() function removes all newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of the supplied string. If these whitespace characters occur in the middle of the string, they are preserved.


1 Answers

$('input').val(function(_, value) {
   return $.trim(value);
});
like image 105
undefined Avatar answered Oct 19 '22 02:10

undefined