带有php数组的下拉菜单

带有php数组的下拉菜单,php,javascript,html,arrays,multidimensional-array,Php,Javascript,Html,Arrays,Multidimensional Array,我想更改此菜单,这样,如果我选择第二个报告,1将显示显示“如果有类型1”的菜单,否则转到第三个菜单,并显示“关于1的文字”。在所有四个菜单中。我认为最好的方法是PHP,但我不知道它的语言 HTML: 这是javascript的一部分 <script language="JavaScript"> var tiporeportlist=document.classic.tiporeport var reportlist=document.classic.report var repor

我想更改此菜单,这样,如果我选择第二个报告,1将显示显示“如果有类型1”的菜单,否则转到第三个菜单,并显示“关于1的文字”。在所有四个菜单中。我认为最好的方法是PHP,但我不知道它的语言

HTML:

这是javascript的一部分

<script language="JavaScript">
var tiporeportlist=document.classic.tiporeport
var reportlist=document.classic.report

var report=new Array()
report[0]=["report1"]
report[1]=["report2"]
report[2]=["report3"]
report[3]=["report4"]

var tipo=new Array()
tipo[0]=["tipo1"]
tipo[1]=["tipo2"]
tipo[2]=["tipo3"]
tipo[3]=["tipo4"]

var banca=new Array()
about[0]=["about1"]
about[1]=["about2"]
about[2]=["about3"]
about[3]=["about4"]

var periodo=new Array()
periodo[0]=["periodo1"]
periodo[1]=["periodo2"]
periodo[2]=["periodo3"]
periodo[3]=["periodo4"]

function getSelected(select) {

    return select.options[select.selectedIndex].value;
}

function getElement(id)  {

    return document.getElementById(id);
}
function popolaSelect(select,opt) {

    switch (opt) {
        case '1':
            var arr = report;
            break;
        case '2':
            var arr = tipo;
            break;
        case '3':
            var arr = about;
            break;
        case '4':
            var arr = periodo;
            break;
        default:
            return;
            break;
    }

    select.options.length = 1;

    for(var i=0; i<arr.length; i++) {                              

        select.options[select.options.length] = new Option(arr[i],i);        
    }
}
</script>

您可以使用php实现这一点,但是如果没有javascript和/或ajax,页面需要每次刷新

出于这个原因,最好使用javascript来实现这一点。
我建议您看看jquery并尝试一下。

这些选项不能用PHP动态更改。每次都应该刷新页面,并且应该通过GET或POST参数或cookie传递值

更简单的实现是使用javascript,如下所示。它应该可以在Internet explorer上正常工作。不过我还没有测试过

HTML:

例如:

您考虑过使用JavaScript吗?StackOverflow不是免费代码服务。是的。。。但php对网页安全性更好吗?任何浏览页面的人都可以看到一些选择框。我知道,但因为我需要在Internet Explorer中查看它,所以将其锁定在javascriptJavascript中,就像在每个标准浏览器中一样。唯一的问题是Internet Explorer无法工作。我可以知道您使用的是哪个版本的Internet Explorer吗?
<script language="JavaScript">
var tiporeportlist=document.classic.tiporeport
var reportlist=document.classic.report

var report=new Array()
report[0]=["report1"]
report[1]=["report2"]
report[2]=["report3"]
report[3]=["report4"]

var tipo=new Array()
tipo[0]=["tipo1"]
tipo[1]=["tipo2"]
tipo[2]=["tipo3"]
tipo[3]=["tipo4"]

var banca=new Array()
about[0]=["about1"]
about[1]=["about2"]
about[2]=["about3"]
about[3]=["about4"]

var periodo=new Array()
periodo[0]=["periodo1"]
periodo[1]=["periodo2"]
periodo[2]=["periodo3"]
periodo[3]=["periodo4"]

function getSelected(select) {

    return select.options[select.selectedIndex].value;
}

function getElement(id)  {

    return document.getElementById(id);
}
function popolaSelect(select,opt) {

    switch (opt) {
        case '1':
            var arr = report;
            break;
        case '2':
            var arr = tipo;
            break;
        case '3':
            var arr = about;
            break;
        case '4':
            var arr = periodo;
            break;
        default:
            return;
            break;
    }

    select.options.length = 1;

    for(var i=0; i<arr.length; i++) {                              

        select.options[select.options.length] = new Option(arr[i],i);        
    }
}
</script>
<form name="classic">
   <select style="width: 20%" id="s1" onchange="choose('s2',this)">
       <option value="0"></option>
       <option value="2">report1</option>
       <option value="2">report2</option>
   <option value="2">report3</option>
       <option value="2">report4</option>
   </select>
   <br /><br />
<select style="width: 20%" id="s2" onchange="choose('s3',this)">
    <option value="0"></option>
    <option value="2">tipo1</option>
    <option value="2">tipo2</option>
<option value="2">tipo3</option>
    <option value="2">tipo4</option>
</select>
<br /><br />
    <select style="width: 20%" id="s3" onchange="choose('s4',this)">
    <option value="0"></option>
    <option value="4">about1</option>
    <option value="4">about2</option>
<option value="4">about3</option>
    <option value="4">about4</option>
</select>
<br /><br />
<select style="width: 20%" id="s4">
    <option value="0"></option>
    <option value="4">periodo1</option>
    <option value="4">periodo2</option>
<option value="4">periodo3</option>
    <option value="4">periodo4</option>
</select>
<br /><br />
function choose(target,option)
{
    var val = option.options[option.selectedIndex].text;
    document.getElementById(target).options[0].innerHTML = val;
}