I'm trying to remove whitespace from an argument passed by a HTML form into a function using the trim() method. The function then lists the addresses that match that postcode.
var postCodes = {
N48LP: {
address: ['59, White Gardens', '54, White Gardens', '52, White Gardens', '55, White Gardens']
}
};
function searchCode(arg2){
arg2.trim();
if(typeof postCodes[arg2] === 'undefined') {
document.getElementById('oldpa').innerHTML = 'Postcode not found';
} else {
// code here which prints the list of addresses
}}};
This doesn't work. Where 'N48LP' works, 'N4 8LP' or 'N 48LP' will result in 'Postcode not found'. Could anyone tell me why? Many thanks.