function() {
var address = $("#postcode").val();
var postcode = address.split(' ');
postcode = "Postcode:"+postcode[(postcode.length-2)];
return postcode;
}
This JavaScript function extracts a postcode from an online form when a user submits a query. I am looking to modify it to retrieve the postcode without the last 2 characters. For instance, if the postcode is "SP10 2RB", the function should return "SP102".