0

This script works in Jquery 1.8.3 but does not work in higher version jquery. Can you help me someone find a problem? Thanks

$(document).ready(function(){
           
    $('#regions').change(function() {
      region = $(this).attr('value');
      $('#discrict').load('ajax.php', { p: region, s: 'okres' } );
      return false;
    });

    region = $('#regions').attr('value');
    $('#discrict').load('ajax.php', { p: region, s: 'okres' } );

});
<select name="region" id="regions">
    <option value="0">region</option>
    <option value="1">region 1</option>
    <option value="2">region 2</option>
    <option value="3">region 3</option>
</select>

<div id="discrict"></div>
APAD1
  • 13,509
  • 8
  • 43
  • 72

1 Answers1

0

I would suggest switching the way you retrieve your field value

region = $(...).attr('value');

to

region = $(...).val();

Though both .attr('value') and .val() behaves the same way in most cases, .val() is more consistent.

What's the difference between jQuery .val() and .attr('value')?

Frank
  • 29
  • 4