@formspark/formtrack
Version:
Automatically inject UTM parameters into your HTML form submissions
25 lines (23 loc) • 536 B
text/typescript
const appendOrUpdateInput = ({
formElement,
id,
name,
value,
}: {
formElement: HTMLElement;
id: string;
name: string;
value: string;
}) => {
let input = document.getElementById(id);
if (!input) {
const newInput = document.createElement("input");
newInput.setAttribute("type", "hidden");
newInput.setAttribute("id", id);
newInput.setAttribute("name", name);
formElement.appendChild(newInput);
input = newInput;
}
input.setAttribute("value", value);
};
export default appendOrUpdateInput;