I've made a jquery/ajax function that updates #courses, sending #fos's .val() and .text(), specifically of the one that is selected, like so:
$('#selling #fos').change(function() { $.post('/ajax/courses', { fos_id: $('#selling #fos').val(), name: $('#selling #fos :selected').text() }, function(data) { $('#selling #courses').html(data); }); });
How do I extend this function so that it uses 'this', allowing me to reuse this function multiple times on the same page? I'm caught because you can't use name: $(this + ' :selected').text()
.
This should work:
$("#"+$(this).attr("id")+" :selected")
it's not pretty but it does the trick :)
or this will work:
$(this).find(":selected").text()
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