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

170
Vistas
Can't loop through a google sheet after 9 (returns 1 then 0)

I'm have having a bit of trouble setting up a dynamic google sheet to fetch data. If the option value goes after 10, it will not work; the code returns the value as a separate 1 then 0. And so on, value 11 would be 1 and 1.

Any help would be awesome and thank you so so much!

<select name="examples" id="selectEvents" class="my-events">
    <option value="" placeholder="select" selected>Select</option>
</select>

<h2 class="event-name" ></h2>
<h3 class="event-info" ></h3>
<script>
    //variables for spreadsheet

    const eventName = document.querySelector('.event-name');
    const eventInfo = document.querySelector('.event-info');

    //variables for sheet
    const sheetId = '1wJp22oIlG29X6FDszaPoh71IvbwrZYoWRqwwYy9gbQg';
    const base = `https://docs.google.com/spreadsheets/d/${sheetId}/gviz/tq?`;
    const sheetName = 'sheet1';
    const query = encodeURIComponent('Select *');
    const url = `${base}&sheet=${sheetName}&tq=${query}`;

    fetch(url)
        .then(res => res.text())
        .then(rep => {
            //Remove additional text and extract only JSON:
            const jsonData = JSON.parse(rep.substring(47).slice(0, -2));

            const dataRows = jsonData.table.rows;
            const select = document.getElementById('selectEvents');

            for (const r of dataRows) {
                select.options[select.options.length] = new Option(r.c[1].v, Number(select.options.length + 1));
            }

            const selectElement = document.querySelector('.my-events');

            selectElement.addEventListener('change', event => {
                for (let i of Object.values(selectEvents.value)) {
                    if (selectEvents.value === i) {
                        eventName.textContent = jsonData.table.rows[i - 2].c[1].v;
                        eventInfo.textContent = jsonData.table.rows[i - 2].c[2].v;
                    }
                }
            });
        });
</script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

May be, try +select.options.length + 1 by adding + in front of select.options.length

select.options[select.options.length] = new Option(r.c[1].v, Number(+select.options.length + 1));
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