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?

Answers


 $("form").children().each(function(){
this.value=$(this).val().trim();
})

will trim all textbox and textarea inside form tag but don't write unnecessary code inside form.


$('input').val(function(_, value) {
   return $.trim(value);
});

Use

var allInputs = $(":input");

to get all form elements. Iterated using each function and trim it.

It will be something like this (not tested)

var allInputs = $(":input"); 
allInputs.each(function() {
        $(this).val($.trim($(this).val()));
    });

$('#yourformid').submit(function(){
 $(':input').each(function(){
   $(this).val($.trim($(this).val()))
})
  return true;
});

Need Your Help

iOS DOxygen adding docSet to Xcode Documents

iphone xcode terminal doxygen docset

Hey Everyone just having a problem with DOxygen, Ive generated my documentation and its allthere, but i find i am unable to add it to Xcode.

What is the meaning of the following?

c arrays

int sampleArray[] = {1,2,3,4,5};