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

102
Visualizações
set the value for aspx label element from javascript

I am calling a Web API using javascript, I have an aspx label element with id "blbtest".

    <asp:Label ID="blbtest" Text="" runat="server ClientIDMode="Static">

I want to store the value of the name variable in this label but I get an error

This is the js code:

       var request = new XMLHttpRequest;
       request.open('GET', "https://hplussport.com/api/products?qty=2");

       request.onload = function () {
       var response = request.response;
       var parsedData = JSON.parse(response);
       console.log(parsedData);
       var name = parsedData[0].name;
       var products = document.createElement('li');
    //products.innerHTML = name;
    //document.body.appendChild(products);
   var lbl = document.getElementById('<%=blbtest.ClientID%>');

  lbl.innerText = name;
  };
  request.send();

The error: Uncaught TypeError: Cannot set properties of null (setting 'innerText') at XMLHttpRequest.request.onload (script.js:14:19)

The commented lines are working. But I want to display the name of the product in the label element when the page loads.

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

0

So, I tried this and it worked :)

    document.getElementById('blbtest').innerHTML = name;
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