简体   繁体   中英

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

 <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 = ?????????????????


    });

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM