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

144
Vistas
want to create a javascript function which on clicking button call php function which create a select option
  1. following is the code with start button and its function which is not working but when im trying to echo hello in place of button tag then the function is working well

      <button onclick="startexam()" id="btn" class="btn btn-primary btn-sm" title="Start 
       exam">Start Exam</button>
      <?php
      function php_func(){  
      echo  '<select class="form-select" aria-label="Default select example"><option > 
      asdf</option></select>'; 
      }
    
      ?>
       <script>
      //function called when user click on start exam button
      function startexam() {
      var result = "<?php php_func(); ?>"
      document.write(result);
      }
      </script>  
    
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

First, you need to understand what the technical difference between PHP and JavaScript is:

JavaScript executes scripts directly in your browser, e. g. Firefox. So, when JavaScript is executed, the page is already loaded.

PHP executes scripts on the server before the page is even in the browser.

So, if you want JavaScript to communicate with the server (the PHP script), you have to make a request to the server. To do so, use AJAX.

How does AJAX work?

From W3Schools:

  1. An event occurs in a web page (the page is loaded, a button is clicked)
  2. An XMLHttpRequest object is created by JavaScript
  3. The XMLHttpRequest object sends a request to a web server
  4. The server processes the request
  5. The server sends a response back to the web page
  6. The response is read by JavaScript
  7. Proper action (like page update) is performed by JavaScript

How to use AJAX?

You can find a complete and clear introduction on W3Schools.

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