Dhwani Dhwani - 6 months ago 16
jQuery Question

Trim textboxes and texareas on submit prevent form to submit

I am trimming all

textboxes and textareas on submit
. It does not work for all view pages.

I have taken simple
html inputs + kendo DropDownList + kendo AutoComplete
in my form.

Below is my submit method which doesn't work, when there are
Kendo UI control
on my form.

$('input[type="submit"]').click(function () {
$('input[type=text], textarea').each(function () {
if($(this).val()!=''){
$(this).val($.trim($(this).val())); //Exception in chrome: paused on exception typeerror. Msg: undefined in not function.
}
});
});


I don't know what's wrong. I found this issue specific to
chrome browser
.

Answer

I don't know what's wrong. So I updated the function as below:

$('input[type="submit"]').click(function () {
   $('#textbox1,#textbox2,#textarea1').each(function () {
     if($(this).val()!=''){
       $(this).val($.trim($(this).val()));
     }
   });
});

I wrote ids of all textboxes and textarea which I need to trim inside each. And it works fine. But still I have question why generalize function didn't work.