Object doesn't support trim method in IE8
internet-explorer-8, javascript, jquery, methods, object
Solution
The `trim` method of `String` was added in IE9, so it's not available in IE8. Use `$.trim()` instead for cross-browser compatibility:
var firstnameObject = {
labelName : $.trim($('#sfield_firstname label').text()),
,validate : generalMethods.validateAlphaFields
}
Problem
I've written a form validation through javascript and it works on all browsers except for ie8. the error I am seeing in IE8 says: Object doesn't support this property or method and points to the line with "var firstnameObject". This error shows right after the page has loaded. there is more code than just this, however I don't want to fill this question up with unnecessary content. Does anyone have any clue/suggestions on why I'm getting this error? Any help is appreciated, Thanks! ``` var generalMethods = { //Validate Alpha validateAlphaFields : function(field){ console.log(field) var currentValue = $(v[field]).val(); console.log('current value:' + currentValue); if (!currentValue || !currentValue.match(/^[A-z]+$/)){ $(v[field]).addClass('Invalid'); $('#s-'+ field).html(eval(field + 'Object.labelName')); } else{ $(v[field]).removeClass('Invalid'); $('#s-'+ field).empty(); } return generalMethods.testSubmit(); } //Enable submit button if parameter === 'enable', else disable submit button ,disableEnable : function(condition){ if (condition === 'enable'){ //Enable submit button $('#form_submit_button, #form-submit-button').removeAttr('disabled'); } } //Test all fields to enable Submit Button ,testSubmit : function(){ var invalidCount = 0; $('#errorMessage span').each(function(){ if ($(this).text().trim().length){ invalidCount++; } }); //Disable submit if any invalid fields if (invalidCount < 1){ generalMethods.disableEnable('enable'); $('#errorMessage').css('display','none'); return true; } else{ $('#errorMessage').css('display','block'); return false; } } } //Validate Fields Objects //===================================================== var firstnameObject = { labelName : $('#sfield_firstname label').text().trim() ,validate : generalMethods.validateAlphaFields } ```