jQuery trim() function in Opera/Safari
in Using jQuery
•
13 years ago
I have a form with a submit button with id 'submit-item'. If a user clicks this button, the fields of this form are read, and sent to a server through an ajax callback. However the code breaks at the point where the trim() function is being used.
Here's my code:
jQuery('#submit-item').click(function(){var description = jQuery('#item-info textarea[name=item[description]]').val();var assignee = jQuery('#item-info select[name=item[responsible]]').val();var duedate = jQuery('#item-info input[name=item[due-date]]').val();if(duedate == 'No due date') {duedate = '';}if(jQuery('#item-info textarea[name=item[description]]').val().trim().length > 0){jQuery('#item-info textarea[name=item[description]]').val('');jQuery('#item-info select[name=item[responsible]]').val('*');jQuery('#item-info input[name=item[due-date]]').val('No due date');jQuery('#item-info input[name=item[due-date]]').addClass('placeholder');jQuery.post(url,{entityId: $content.id,action: 'add',completed: 'false',description: description,assignee: assignee,duedate: duedate},function(data) {var x = jQuery('.item, .content').size();addItem(x, description, assignee, duedate);});}return false;});
1