Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

396
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda