最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to get the selected value and key from an html dropdown list in javascript on php - Stack Overflow

programmeradmin4浏览0评论
 <select id="facetList" style="width:120px;" class="text ui-widget-content ui-corner-all">
        <?php
        foreach($claAddArray as $k => $v)
        {
           echo "<option value=\"$k\">$v</option>";
        }
        ?>   
        </select>




$("#btnSubmit").click(function() {

    var $fId = ?????????????????


    });
 <select id="facetList" style="width:120px;" class="text ui-widget-content ui-corner-all">
        <?php
        foreach($claAddArray as $k => $v)
        {
           echo "<option value=\"$k\">$v</option>";
        }
        ?>   
        </select>




$("#btnSubmit").click(function() {

    var $fId = ?????????????????


    });
Share Improve this question edited Dec 22, 2010 at 12:55 Shakti Singh 86.4k21 gold badges139 silver badges155 bronze badges asked Dec 22, 2010 at 12:50 Ahmad FaridAhmad Farid 14.8k45 gold badges98 silver badges138 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

jQuery's .val() will return the currently selected option's value if run on the select list itself. In your case $("#facetList").val();

use $("#facetList option:selected").text(); for the text of the option tag.

document.getElementById('facetList').options[document.getElementById('facetList').selectedIndex].value
发布评论

评论列表(0)

  1. 暂无评论