Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
How to use an if statement to only collect forms fields that contain an '@' symbol in?

I'm currently collecting form abandonments from my website using the javascript code below within the tag manager of analytics software (Piwik pro).

It currently works great, however, I'm now trying to make it so that only emails with an '@' collect and nothing else.

I'm thinking that an if statement that has .includes("@") will do the job, however as I'm a beginner and I did not write this code, I am struggling to make it work. The below shows what I've tried (amongst many other attempts) and it either continues to collect everything or doesn't collect anything...

(Also I'm unsure if _paq.push is used outside of the analytics software I use, but that line creates a custom event within Piwik pro.)

formFields = ['input_3_1','input_3_2','input_3_3','input_3_4']

  let formFieldText = document.getElementById('input_3_1').value
  let fieldHasAtSymbol = formFieldText.includes("@")
  
  if (fieldHasAtSymbol = 'true') {

        function trackUnsubmittedField(fieldId){
          let formField = document.getElementById(fieldId)
          if(formField.nodeName==="SELECT"){
            formField.addEventListener('change',()=>{
              _paq.push(['trackEvent','formAbandonment',fieldId,document.getElementById(fieldId).value])
            })
          }
          else{
            formField.addEventListener('focusout',()=>{
                _paq.push(['trackEvent','formAbandonment',fieldId,document.getElementById(fieldId).value])
            })
          }
        }
  }
        formFields.map(element=>trackUnsubmittedField(element))

I've also tried using the same form field variable that's declared within the function by placing a .includes() if statement within it, but no luck.

formFields = ['input_3_1','input_3_2','input_3_3','input_3_4']

        function trackUnsubmittedField(fieldId){
          let formField = document.getElementById(fieldId)
          
                if (formField.includes("@") = "true") {
          
          if(formField.nodeName==="SELECT"){
            formField.addEventListener('change',()=>{
              _paq.push(['trackEvent','formAbandonment',fieldId,document.getElementById(fieldId).value])
            })
          }
          else{
            formField.addEventListener('focusout',()=>{
                _paq.push(['trackEvent','formAbandonment',fieldId,document.getElementById(fieldId).value])
            })
                }
        }
  
        formFields.map(element=>trackUnsubmittedField(element))

There's probably a lot wrong with the code I added onto this but any help would be appreciated.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda