Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

353
Visualizações
searchParams.get returning "Null" when values are present

I'm trying to grab URL params from a page link to prepopulate a form in an iFrame, but am struggling with the params returning 'null' and need some guidance. So far, the script appears to work by populating the form with "null", however, it is unsuccessfully populating params that have valid values in my URL. The javascript below 'f.src' is scripting provided by my forms service.

(I apologize for the ugly console.logs, but am using those for troubleshooting.)

***UPDATE: With my updated code, per user suggestion, I updated my .get statements to specify the param with a string, but it's still returning 'null'.

try{
        var endpoint = "https://forms.myformsite.com/";
        console.log(endpoint);
        var url_string = "https://my.site.com/landingpage?fname=Jeff&lname=Bezos&email=jeff@amazon.com&company=Amazon&title=Founder"; /*window.location.href;*/
        console.log(url_string);
        var url = new URL(url_string);
        console.log(url_string);
        var fname = url.searchParams.get('fname');
        console.log(fname);
        var lname = url.searchParams.get('lname');
        console.log(lname);
        var email = url.searchParams.get('email');
        console.log(email);
        var company = url.searchParams.get('company');
        console.log(company);
        var title = url.searchParams.get('title');
        console.log(title);
        var formURL = endpoint+"&fname="+fname+"&lname="+lname+"&email="+email+"&company"+company+"&title="+title;
        console.log(formURL);
        var f = document.createElement("iframe");   
        f.src = formURL;
        console.log(f.src);
        f.style.border = "none";
        f.style.height = "878px";
        f.style.width = "90%";
        f.style.transition = "all 0.5s ease";
        var d = document.getElementById("divFormID");
        d.appendChild(f);
        window.addEventListener('message', function() {
            var evntData = event.data;
            if (evntData && evntData.constructor == String) {
                var zf_ifrm_data = evntData.split("|");
                if (zf_ifrm_data.length == 2) {
                    var zf_perma = zf_ifrm_data[0];
                    var zf_ifrm_ht_nw = (parseInt(zf_ifrm_data[1], 10) + 15) + "px";
                    var iframe = document.getElementById("divFormID").getElementsByTagName("iframe")[0];
                    if ((iframe.src).indexOf('formperma') > 0 && (iframe.src).indexOf(zf_perma) > 0) {
                        var prevIframeHeight = iframe.style.height;
                        if (prevIframeHeight != zf_ifrm_ht_nw) {
                            iframe.style.height = zf_ifrm_ht_nw;
                        }
                    }
                }
            }
        }, false);
    } catch (e) {}
})();```


about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

For all .get() calls, you're passing in an (undefined) variable instead of a string:

var fname = url.searchParams.get(fname);

This should be:

var fname = url.searchParams.get('fname');
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda