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

399
Views
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 answers
Answer question

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 Report
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!