Return Email address from 1 of two forms

There are two forms. I am trying to retrieve the email address entered from whichever form is filled out. The following code only returns “regsubmit_btn or regsubmit_popup”.

function () {
    var regsubmit_btn = document.getElementById('reg_email').value;
      var regsubmit_popup = document.getElementById('reg_email_popup').value;
    if (regsubmit_btn)
        return reg_email;
   else if (regsubmit_popup)
        return reg_email_popup;
    else
        return "email blank";}

Show us the html as you need to get the value entered into the input element, not the submit button.

1 Like

Dennis, this is for a Google Tag Manager variable. I figured it out. The following code worked for me.

function () {
    var regsubmit_btn = document.getElementById('reg_email').value;
     var regsubmit_popup = document.getElementById('reg_email_popup').value;
   
if (regsubmit_btn != "")
{
        return regsubmit_btn;
}
  else if (regsubmit_popup  != "")
{
        return regsubmit_popup;
}
      else
{
        return "email blank";
}
}

@demetriusmcclain for future reference, when you post code in the forum, you need to format it. To do so you can either select all the code and click the </> button, or type 3 backticks ``` on a separate line both before and after the block of code.

I have done it for you this time.

1 Like

Thanks you for letting me know. As you can tell. I’m new to this. :blush:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.