duanguangsong2380 2014-02-03 00:17
浏览 55
已采纳

如何从html脚本代码中获取php中的select-option值?

First, I made script-html including 2 select-option menus as like below.

    <script>
    ....
    var selectedLang1 = document.getElementById('lang1').value;
    var selectedSubject = document.getElementById('subject').value;
    xmlhttp.open("GET","livesearchgroup_"+selectedLang1+"_"+selectedSubject
            +".php?q="+str,true);
   xmlhttp.send();
    }
   </script>

    <select name="lang1" id="lang1">
    <option value="co">한국어</option>
    <option value="en">English</option>

    <option value="af">Afrikaans</option>

    <option value="ar">Arabic</option>

    <option value="az">Azerbaijani</option>

    <option value="be">Byelorussian (Belarusian)</option>
    <option value="bg">Bulgarian</option>
    <option value="bh">Bihari</option>
    </select>

    <select name="subject" id="subject" size="2" style="width:45%;" >
     <option value="a">Infection : bacteria and virus </option>

     <option value="b">Infection : virus, fungus and etc</option>
     <option value="c">Malignant neoplasm</option>
     <option value="d">Benign neoplasm and blood </option>

     <option value="e">Endocrine, nutrition and metabolism </option>
     <option value="f">Mental and behavioral disorders</option>

     <option value="g">Nervous system</option>
     <option value="h">Eye and ear</option>
     <option value="i">Circulatory system</option>
    </select>
    <form>

     <input type="text" size="30" onkeyup="showResult(this.value)">
    </form>
    <div id="livesearchgroup"></div>

And my php code is below.

  <?php
 $lang1=$_POST['lang1'];
 $subject=$_POST['subject'];

 $xmlDoc=new DOMDocument();
 $xmlDoc->load("ds_".$subject."_".$lang1.".xml");

But select-option values don't come to php code. How can I receive those values in php??

展开全部

  • 写回答

3条回答 默认 最新

  • duanaidang6197 2014-02-03 00:24
    关注

    The Javascript should be:

        xmlhttp.open("GET","livesearchgroup.php?q="+str+'&lang1='+selectedLang1+"&subject="+selectedSubject,true);
    

    The parameters have to be put after ?, not as part of the script name (unless you have a server rewrite rule that does this automatically).

    And in the PHP, you should use $_GET, not $_POST.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?