I have a problem that I struggled with all morning, so I felt it was time to help! I have a javascript function that receives a value entered by a user in an autocomplete field, uses AJAX to send this value to a php script that queries the database, and then populates the next field with possible parameters. The problem is that all this works fine when I hard code the selected option:
var selected="Ed Clancy";
but not when he pulls it out of the window, like this:
var selected = this.getValue();
I tried debugging this with a warning window, and the same line appears in both blocks, so I'm completely puzzled! Any ideas? Full code below:
$(riderSelected).on('selectionchange', function(event){
var selected = this.getValue();
alert(selected);
$('#nap4').removeAttr('disabled');
$('#nap4').empty();
$('#nap4').append($("<option>-select-</option>"));
$.ajax({
type: "GET",
url: 'getbiketype.php',
data: { name: selected },
success: function(data) {
console.log(data);
$('#nap4').append(data);
}
});
});