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

397
Vistas
Load Variables from (Javascript) .js file using PHP?

New to PHP so apologies in advance for the simple question.

I have a Javascript file (.js). which contains a list of values. i.e.

var item1 = 1.00;
var item2 = 25.00;
var item2 = 35.00;          

Can can i use PHP to read this file and import the data in an array with values.

item1 = 1.00  
item2 = 25.00    
item2 = 35.00    

and then I would like to be able to GET the PHP script with.
xyz.com/file.php?id=item1. and be able to send back the associated value.

I now this is simple, but i am having very little success as to where to start. I reviewed https://www.php.net/manual/en/function.parse-ini-file.php. but I think it it needs the file to be read to have .ini extension which is not an option in my situation.

Any help,guidance,advise would be greatly appreciated.

Thank you in advance.

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

0

  1. I would create array from variables
  2. Loop through array to create inputs
  3. Put array values into input values
  4. Submit form to PHP

var item1 = 1.00;
var item2 = 25.00;
var item3 = 35.00; 

let array = [];

array.push(item1)
array.push(item2)
array.push(item3)

let inputs = ``;
for(let i = 0; i <= array.length - 1; i++){
    inputs += `
    <div>
        <input type="text" value='${array[i]}' />
    </div>
  `
}

document.getElementById("inputs-here").innerHTML = inputs;
<form method="post" action="your-route-here">
  <div id="inputs-here"></div>
  <input type="submit" value="submit" />
</form>

and after you can capture it in PHP, just try this and you can take from there

print_r($_POST)

You can also create these inputs as "hidden" and submit without button, using JavaScript automatically, but that's different subject.

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