Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
How do I get the id of a button to be passed to and appended to a URL thus loading from a JSON?

When I click a button I want to pass that button poke.pid to add that to a URL to get some info;

The button

list = list + `<a href="#listing" id="${poke.pid}" 
            onclick="getPo('${poke.pid}')" 
            class="collection-item">${poke.name}</'a>`;

The code below is what I have;

async function getPo(url){
   try {
    let response = await fetch(url);
    let result = await response.json();
    displayPok(result);
    } catch (e) {
        console.log(e);
    } 
}
//the URL in question
getPokemon(('URL/somethinghere/').append('${poke.pid}'));

function displayPok(pok){
    let result = document.querySelector('#result');
    let html = ' ';
    html = html +
        `<div href="#result" id="${pok.pid}" class="card col m12 l10 offset-l1" style="margin-top: 20px">
                <div class="card-image" >
                    <img class="teal" src="${pok.image}" alt="Bulbasaur Image">  
                </div>
                <div class="card-content">
                    <span class="card-title"><p>${pokemon.name}</p></span>
                    <p> Type1: ${pok.type1}</p>
                    <p> Weight: ${pok.weight}</p>
                    <p> Height: ${pok.height}</p>
                    <a onclick="catchPokemon(1)" id="catchBtn" style="position:absolute; 
 right:15px; bottom:80px"  
                        class="btn-floating btn-large waves-effect waves-light red">
                        <span class="iconify" style="font-size:40px; margin-top:8px" data-icon="mdi-pokeball" data-inline="false"></span>
                    </a>
                </div>
            </div>`;
    result.innerHTML = html;
}

My question is when I click the button can I pas that pid by appending it to the url in question and thus load an item from the subsequent json? If so how?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I found it:

//let response = await fetch(`https://pokedextr-api.herokuapp.com/pokemon/${pid}`);
//let result = await response.json();
let result = await sendRequest(`https://pokedextr-api.herokuapp.com/pokemon/${pid}`, 'GET');

Any one of the options above would work.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!