xhr.onreadystatechange = function() { if (xhr.readyState == 4 && xhr.status==200) { token=xhr.responseText; //add value/field to form txCvv = txJ$(".cvv").val(); var MyForm = txJ$(".submit").closest("form"); if (txJ$('#cipherText').length > 0) { txJ$('#cipherText').val(txCryptData); } else { txJ$('').attr({ id: 'token', name: 'token' }).val(token).appendTo(MyForm); txJ$('').attr({ id: 'cvv', name: 'cvv' }).val(txCvv).appendTo(MyForm); } //scrub data that we do not want to post txJ$(".data").removeAttr('name'); txJ$(".cvv").removeAttr('name'); } } xhr.open('POST', 'tokenize.php', true); xhr.send(params);