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

152
Visualizações
Uncaught ReferenceError: buyNft is not defined at HTMLAnchorElement.onclick

Am I missing to add some script or what? I am getting error from title. How can I solve this, if you can help me, I would be grateful. I tried adding different scripts, but I amgetting the same error.

 <a onclick="buyNft({{$nft->id}})">{{trans('nft.buy')}}</a>
    
        @push('scripts')
            <script>
        
                function buyNft(nftid) {
                    swal({
                        title: "Are You Sure?",
                        text: "Do you want to buy this nft?",
                        type: 'warning',
                        showCancelButton: true,
                        showConfirmButton: true,
                        confirmButtonColor: '#3085d6',
                        cancelButtonColor: '#d33',
        
        
                    }).then((result) => {
                        if (result) {
                            axios.post("/buythisnft/" + nftid).then(response => {
                                window.location.reload();
                            });
        
                        }
                    });
        
                }
            </script>
        @endpush
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your buyNft-function needs to be declared BEFORE you echo out any element with "onclick=buyNft()":

@push('scripts')
  <script>
      function buyNft(nftid) {
          // ...
      }
  </script>
@endpush
 
 <a onclick="buyNft({{$nft->id}})">{{trans('nft.buy')}}</a>

UPDATE: This is an example using a script at the bottom of the page which creates an eventlistener for click-events:

document.addEventListener("click",e => {
  if(e.target.closest(".buyNft")){
    e.preventDefault();

    alert("You want to buy an NFT.")
    
    //... Replace with your own functions ...
  }
})
<a class="buyNft" href="#">Buy that NFT</a>
<br /><br />
<a href="#">Some other link on this page</a>

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