Suhrob Samiev
Suhrob Samiev

Reputation: 1547

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

Upvotes: 0

Views: 1269

Answers (1)

Flambino
Flambino

Reputation: 18773

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/

Upvotes: 3

Related Questions