jQuery get the selected dropdown value on change

Viewed 79473

I'm trying to get the value of a dropdown on change (and then change the values in a second dropdown).

EDIT: Thanks for all the replies, i've updated to add the () but the code is returning nothing, not null or undefined just a blank alert window

However when I alert it out the attr(value) is undefined.

Any ideas on what i'm missing?

Here is my code:

<script type="text/javascript">
            $(document).ready(function() {

                var roomID = "0"
                $('.dropone').load('ajaxdropdown.aspx');
                $('.droptwo').load('ajaxdropdown.aspx?drpType=room&roomid=' + roomID);

                $('.dropone').change(function() {
                var ts = new Date().getTime();
                alert($(this).val)

                    $(".droptwo").empty();
                    $(".droptwo").load("ajaxdropdown.aspx?drpType=room&roomid=" + $(this).attr("value") + "&ts=" + ts);
                });

            });        
        </script>
6 Answers

Check jQuery and Javascript methods here to get Single/ Multiple selected values in the Drop Down

Demo Link

jQuery Method: Method to get Selected Value from a select box:

HTML

<select id="singleSelectValueDDjQuery" class="form-control">
    <option value="0">Select Value 0</option>
    <option value="8">Option value 8</option>
    <option value="5">Option value 5</option>
    <option value="4">Option value 4</option>
</select>

<input type="text" id="textFieldValueJQ" class="form-control"
    placeholder="get value on option select">

jQuery

$("#singleSelectValueDDjQuery").on("change",function(){
    //Getting Value
    var selValue = $("#singleSelectValueDDjQuery").val();
    //Setting Value
    $("#textFieldValueJQ").val(selValue);
});

Method to get Selected Value Option Text from a select box:

HTML

Select Value 0 Option value 8 Option value 5 Option value 4

<input type="text" id="textFieldTextJQ" class="form-control"
                placeholder="get value on option select">

jQuery

$("#singleSelectTextDDjQuery").on("change",function(){
    //Getting Value
    var selValue = $("#singleSelectTextDDjQuery :selected").text();
    //Setting Value
    $("#textFieldTextJQ").val(selValue);
});
Related