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

194
Vistas
How to change iframe src when a button is pressed

I tried to change src of an iframe, to change trailers, but after trying to utilize the answer of a different post: iframe src change on button click but I still couldn't get it to work, it keeps saying: "newSrc is not defined at HTMLButtonElement.onclick (index)(9:65)"

I want to thank everyone for their comments, I found the problem and solved it, I forgot to link the javascript on the page I was working on, the dumbest mistake that I could've made

Thank you Chris for helping with extra tips and Nermin for making me realise my dumb mistake

function newSrc() {
  var e = document.getElementById("Menu_trailers");
  var newSrc = e.options[e.selectedIndex].value;
  document.getElementById("trailers").src=newSrc;
}
      <figure class="trailer">
        <iframe src="https://www.youtube.com/embed/sfAc2U20uyg" id="trailers"> </iframe>
      </figure>
      <section class="button_trailer">
        <select id="Menu_trailers">
          <option value="https://www.youtube.com/embed/sfAc2U20uyg">Trailer 1</option>
          <option value="https://www.youtube.com/embed/o-L1mMZ31hM">Trailer 2</option>
        </select>
        <button onclick="newSrc();" class="button_next_trailer">Change trailer</button>
      </section>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Here is the JS code to get the src from the select menu, then set it to the iframe element

function newSrc() {
  // Get The Select Menu Element
  var e = document.getElementById("Menu_trailers");
  // Set Select Menu Value (Selected Option) To Be The src Of The iframe
  document.getElementById("trailer").src = e.value;
}
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