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

151
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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