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
Formulario PHP de varias páginas que obtiene una variable PHP en JavaScript en una página diferente

Tengo un formulario de trabajo con muchas variables y necesito una opción para uno o dos solicitantes. La solución en la que estoy trabajando es tener los campos HTML ocultos para el segundo solicitante hasta que se marque una casilla de verificación. Tengo ocultar y mostrar funcionando en la primera página y tengo el estado de la casilla de verificación configurado como una variable en PHP, pero no puedo entender cómo obtener la variable PHP en las siguientes páginas para activar automáticamente el segundo solicitante. campos. Con cosas pasadas, intenté buscar en las herramientas de desarrollo en Chrome, me dice que la variable regresa vacía; sin embargo, si uso la misma variable en la misma página en el HTML, no en el JavaScript, muestra claramente el anuncio "activado".

Lo último que intento es convertir la variable a JSON, pero aún no tuve suerte.

 <!DOCTYPE html> <html> <body> <!-- p elements only for testing to see outputs --> <p id="test"> <?php echo $twoapplicants ?></p> <p id="test2"></p> <!-- something to look at after endless page refreshs --> <h2>Two Applicants Test Page</h2> <!-- Hidden untill Toggleextrafields() is triggered fields need to be present on page but only showed if a variable from the previous page is "on" --> <p class="extrafields" style="display:none">now you see me</p> <script> //$twoapplicants defined as on on another page in a PHP run multipage form <?php $twoapplicants = "on"; ?> //test for value set on previous page on page load window.onload = pageload(); // trigger Toggleextrafields if variable is equal to "on" function pageload(){ var a =<?php echo json_encode($twoapplicants); ?>; var b = JSON.parse(a); document.write (b); document.getElementById('test2').innerHTML = b; if(b === "on"){ Toggleextrafields(); } else {extrafieldsoff(); } } // toggle extra fields and make them visible if they aren't already (this already works) function Toggleextrafields() { var x = document.getElementsByClassName("extrafields"); var i; for (i = 0; i < x.length; i++){ if (x[i].style.display === "block") { x[i].style.display = "none"; } else { x[i].style.display= "block"; } } } // hides extra fields if they aren't hidden already and the trigger isn't there function extrafieldsoff() { var x = document.getElementsByClassName("extrafields"); { x.style.display = "none"; } } </script> </body> </html>
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!