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

215
Views
¿Por qué no puedo agregar una nueva opción a mi menú desplegable de selección de html en js?

Mi html:

 <p id="book_no"><select name="books" id="bno" onclick="get_books()"> </select>&ensp;<i class="fa fa-solid fa-plus" style="cursor: pointer;" onclick="add_book()"></i></p>

Mi javascript:

 function get_books(){ let $select = $("#bno"); return $.ajax({ url: '/edit_qrtr/server.php', type: 'POST', data:{"input": "get_books"}, dataType: 'json', success: function(response) { let selectedValue = $select.val(); let html = response.filter((e, i, a) => a.indexOf(e) === i).map(item => `<option value="${item}">${item}</option>`); $select.html(html).val(selectedValue); }, complete: function() {} }); } function add_book(){ get_books().done(() =>{ let $select = $("#bno"); let b = prompt("Please enter the new book no"); if(b!=null) $select.append(`<option value="${b}">${b}</option>`); }) }

El problema es que, cuando intento agregar un nuevo libro, no se inserta en la lista. ¿Cómo soluciono este problema? Por favor, ayúdame.

EDITAR: En la función get_books() , estoy buscando todos los números de libros que ya están en mi tabla sql. En la segunda función add_book() , estoy tratando de agregar un nuevo número de libro, que no está presente en la lista de libros ya obtenida.

about 4 years ago · Juan Pablo Isaza
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!