You're trying to capture a visitor’s email from the first Webflow form submission and automatically pre-fill it in a later form. If your current script is returning "undefined," the issue is likely due to incorrect variable storage/retrieval or that the script is running before the value is available.
To fix this, follow these steps:
</body> tag (inside an Embed element):
Example:
```javascript
<script>
document.addEventListener("DOMContentLoaded", function () {
var form = document.querySelector("#emailCaptureForm"); // Replace with your form’s ID
if (form) {
form.addEventListener("submit", function (e) {
var emailInput = form.querySelector("input[type='email']");
if (emailInput && emailInput.value) {
localStorage.setItem("storedEmail", emailInput.value);
}
});
}
});
</script>
```
#emailCaptureForm matches the ID of your form element in Webflow.
```javascript
<script>
document.addEventListener("DOMContentLoaded", function () {
var savedEmail = localStorage.getItem("storedEmail");
if (savedEmail) {
var emailField = document.querySelector("#emailFieldLater"); // Replace with your field’s ID
if (emailField) {
emailField.value = savedEmail;
}
}
});
</script>
```
#emailFieldLater matches the id of your email input on the second form.id.
emailInput.value or emailField.value returns undefined.DOMContentLoaded to delay script execution until the DOM is fully available.
To transfer an email from one Webflow form to another, store the value in localStorage on the first form’s submission and then retrieve it on the second form page using JavaScript. Double-check that your form and input field selectors (#id) are accurate and that the email value is properly submitted before testing on the next form page.