Slightly confused by this problem. I have written this function to replace punctuation in input elements:
function punctuationReplace(element){
var elementToChange = document.getElementById(element);
elementToChange.value = elementToChange.value.replace(/\"/g, '');
elementToChange.value = elementToChange.value.replace(/\'/g, '');
elementToChange.value = elementToChange.value.replace(/&/g, 'and');
elementToChange.value = elementToChange.value.replace(/</g, '');
elementToChange.value = elementToChange.value.replace(/>/g, '');
}
<input type="text" id="IPR_FNM1" name="IPR_FNM1" value="" maxlength="30" size="31" placeholder="Forename 1" onblur="punctuationReplace(this)"/>
When I manually run the function in the browser console with the relevant ID as the argument, it works. And when inside the function I add the line alert(element.id);, I get an alert containing the correct element ID. So I am confused as to why the above punctuationReplace function won't work when I call it using onblur="punctuationReplace(this)".
I'm sure there is a simple solution but no idea what it is.