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

71
Visualizações
My newly created html element to show Item Size on each order detail row only shows on the top row

Edited with my progress:

Noob here. I know just enough javascript to get myself in trouble. Case and point: my webstore has an existing template for a packing list and I'm trying to add the item Size to it.

For each ordered item, the packing list has an element [itemname] which contains the Item + Size. I wrote a function that passes [itemname], breaks out just the size, and returns it. I'd like to display that size on the line item beside quantity, or anywhere on the detail line.

The itemSize tag is only showing on the top detail line. It is not inserting where it should.

Spent way too much time on this issue. Can anyone help?

            <!--START: items-->
        <div class="row">
            <div class="invoice-id">[id]</div>
            <div class="invoice-items">
                [itemname]<!--START: warehouse_location--><br />
                [warehouse_location] [warehouse_aisle] [warehouse_bin] [warehouse_custom]<!--END: warehouse_location-->
            </div>
  


  <div id="itemSize"></div>

  <div class="invoice-qty">[numitems]<br /> </div>

    <div class="clear"></div>
        </div>
<hr>

  <script language="JavaScript" type="text/javascript" >

  function myFunction(txt){
    var str = txt.substr( txt.indexOf(";")+1,  txt.length -  txt.indexOf(";"));
    console.log(str);

    var newDiv= document.createElement("div");

    var newContent = document.createTextNode(str);
                                          
    newDiv.appendChild(newContent);

    var currentDiv = document.getElementById("itemSize");
    var nextDiv = document.getElementById("invoice-qty");
    currentDiv .insertBefore(newDiv, nextDiv );                                            
                                  }

    myFunction("[itemname]");

          </script>

        <!--END: items-->

This is the packing list output. The "bag of 6 tarts" or "7oz med" should be on each line beside the respective item.

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

0

Attribute id should be unique. You can generate a dynamic id, something like: id-[index] and then in your JS function target the id that matches each item.

    function myFunction(txt, index) {
        var str = txt.substr( txt.indexOf(";")+1,  txt.length txt.indexOf(";"));
        var newDiv= document.createElement("div");
        var newContent = document.createTextNode(str);
        newDiv.appendChild(newContent);
        var currentDiv = document.getElementById(`itemSize-${index}`);
        var nextDiv = document.getElementById("invoice-qty");
        currentDiv .insertBefore(newDiv, nextDiv );
    }
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