I need to trim all trailing white spaces from the text elements of the form. I need to do this with a minimum number of steps. As soon as I click onsubmit, it should trim all spaces and then perform further operations. Is there a script? If not, you can help me achieve my goal. Currently, I need to manually identify each item, and then do a similar cropping.
var username = myform.elements['username'].value; username.trim();
How to generalize it?
$("form").children().each(function(){ this.value=$(this).val().trim(); })
will clip all text fields and textarea inside the form tag, but not write unnecessary code inside the form.
$('input').val(function(_, value) { return $.trim(value); });
Using
var allInputs = $(":input");
to get all the elements of the form. Iterates using each function and truncates it.
It will be something like this (not verified)
var allInputs = $(":input"); allInputs.each(function() { $(this).val($.trim($(this).val())); });
$('#yourformid').submit(function(){ $(':input').each(function(){ $(this).val($.trim($(this).val())) }) return true; });
Source: https://habr.com/ru/post/918342/More articles:What does the statement ("void) startGuardBegin" do; do? - c ++#Define VS Variable - cCropping an ellipse from an image - image-processingStack full stack detection - c ++NHibernate Overcoming NotSupportedException - linqHow to automatically remove orphans when merging a deserialized object graph in doctrine2? - merge403 Access denied in Tomcat - linuxSolr-composite text tokenizer - results are processed as an OR expression - filterUse a field from a linked model as a display field in CakePHP - cakephpDeploying Eclipse Web Applications with Tomcat: Providing Multiple Project Dependencies? - javaAll Articles