drbxr86044 2016-06-24 20:20
浏览 89

如何从PHP获取数组并使用数组中的值?

I have a dropdown menu and javascript inside index.html. For clarity I removed most of the options (there're over 20). It sends the dropdown menu selection to engine.php

index.html

<script>
function refreshpage(e)
{   
    var e = document.getElementById("sr");
    var snk = e.options[e.selectedIndex].value;
    window.location.href = "engine.php?selectedOption=" + snk;
}
</script>

<h4>Select your option</h4>
    <form action="" id="optionform" onsubmit="return false;">
        <select class="item_options" id="sr" name='sr' onchange="refreshpage(this);">
             <option value="None">Select option</option>
             <option value="Option1">Option 1</option>
             <option value="Option1">Option 2</option>
             <option value="Option1">Option 3</option>
        </select>
    </form>

When you select an option, it sends the option to engine.php

engine.php

<?php
$option1 = 5;
$option2 = 10;
$final = array($option1, $option2);
if($_GET["selectedOption"] == 'Option1')
{
    $option1 = 20;
    $option2 = 20;

}
?>

How can I send $final back into index.html and use javascript to use the values in the $final array ($option1 and $option2). I basically want to refresh index.html and use the new, updated values ($option1 = 20; $option2 = 20;)

  • 写回答

4条回答 默认 最新

  • dongyue9864 2016-06-24 20:27
    关注

    You can use ajax as @Hackerman suggested and is likely the approach I would use.

    Alternatively, you can add a redirect to the end of your engine.php page and send the user back to the index page.

    $newURL = "index.php?values=$newValues";
    header('Location: '.$newURL);
    

    To take this approach, your index page will need to process the values argument upon load.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog