Categories
Javascript Snippets

Javascript Find and replace text in input fields

One of my recent jobs involved doing a lot of data entry and manually sanitising a lot of data and would use this snippet all the time.

var input = document.getElementsByTagName('input');
for(i=0;i<input.length;i++){
    input[i].value = input[i].value.replace("Animal","Lecturer");

}
var area = document.getElementsByTagName('textarea');

for(a=0;a<area.length;a++){

    area[a].value = area[a].value.replace("Animal","Lecturer");

}