I am trying to get my field to format after data is placed in it from an AJAx query. I just figured out how to use Ajax about 20 minutes ago so I'm fairly noobish still towards it.
document.getElementById("mpMAC").value = xmlhttp.responseText;
Above is the field that needs to be formatted. It returns a MAC address based on a SN provided in a separate field. The call is functioning properly and I have my code that I've been using to format the field but it is based on Key Up and Change events.
Here is my code for the formatting part that I've been using for a few weeks now
function formatMAC(e) {
var r = /([a-f0-9]{2})([a-f0-9]{2})/i,
str = e.target.value.replace(/[^a-f0-9]/ig, "");
while (r.test(str)) {
str = str.replace(r, '$1' + ':' + '$2');
}
e.target.value = str.slice(0, 17);
};
$("#mpMAC").on("keyup change", formatMAC);
I'm not sure how to run the function automatically when the data is placed in there from the ajax call.
Any and all help is much appreciated. Thanks!