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>
                The change event is fired for <input> , <select> , and <textarea> elements when the user modifies the element's value.
val is a method, not a property.
use it like    val()
If you are using it many places, i would assign it to a local variable and use it thereafter.
Also you can use the $.now() function to get the unique time stamp. It is equal to DategetTime();
$('.dropone').change(function() {    
    var item=$(this);
    alert(item.val())
    $(".droptwo").empty();
    $(".droptwo").load("ajaxdropdown.aspx?drpType=room
                        &roomid=" +item.attr("value") + "&ts=" + $.now());
});
                        $('.dropone').change(function() {
  var val = $(this).val(); 
  // OR
  var val = this.value;
})
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With