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

141
Views
Get a value out of a php array in a js function

I'm pretty new to this. I'm trying the following. I have a select input dropdown in the productionCalculator.php. Whenever it's input changes, I call a js function. This function needs an array out of a php file. I already learned a lot (like I have to use include unlike require f.e.) but I the only "value" I get back is null. When I define a string variable directly in the called php file, it works, but if I access the array in the other php the returned value is null. And I can't call the array php file directly, because echo would write the result on the site. I'm really stuck. Pls help, I thank you so much.

There a 4 files involved:

The selection in the productionCalculator.php

<body>
        <img src="https://images.evetech.net/types/1002/bp" id="bpoImage">
            <select name="bpoDropdown" id="bpoDrop" onchange="SetBpoImage()">
            <?php 
            foreach ($blueprintDict as $key => $value) { ?>                
                <option value=<?php echo $key?>><?php echo $key?></option>
                <?php 
            }
        ?>
        </select>
    </body>

The js function which is called, when the dropdown changes. This is a .js file

function SetBpoImage()
{
    var e = document.getElementById("bpoDrop");
    var index = e.selectedIndex;

    var req = new XMLHttpRequest(); 
    req.onload = function() {
    console.log(this.responseText); 
    };
    req.open("get", "assets/getBlueprintDict.php", true); 
    req.send();
}

The getBlueprintDict.php

<?php
require("assets/blueprintDict.php");
echo json_encode($blueprintDict); 
?>

And the blueprintDict.php I need in the js function.

<?php 
$blueprintDict=array(
"Typhoon" => 1,
"Dominix" => 2,
"Erebus" => 3,
"Small Shield Extender I" => 4,
"Survey Scanner I" => 5,
);
?>

Folder Structure: main folder main folder

assets folder assets folder

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!