简体   繁体   中英

Can't get form's select element value using jQuery

I am able to get input element's value using var flt=$("#flt"+rowID).val();

but cannot get select elements value

here is my php code

<?php
    $AC= & getAC();
    while ($rowAC=mysql_fetch_array($AC)){
        $i++;
        if ($rowAC['acode']==$row['TPE']){
            echo "<option value='{$rowAC['acode']}' selected='selected'>{$rowAC['name_ru']}</option>";  
        }else{
            echo "<option value='{$rowAC['acode']}'>{$rowAC['name_ru']}</option>";                  
        }

    }
?>    

I am generating list using this php code but

cannot even getting it's text value coding in such a way

var tpe=$("#tpe option[value='2']").text();
window.alert(tpe);

I am concerned only to get it's option value!!! How to get it???

After some quick testing, it appears that value() only works on the select element itself. To get the value of the different option elements, you can use attr('value') on the option elements themselves.

Very quick demo: http://jsfiddle.net/y9Dqg/2/

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