Saturday, May 25, 2024
 Popular · Latest · Hot · Upcoming
44
rated 0 times [  49] [ 5]  / answers: 1 / hits: 35977  / 14 Years ago, sat, september 18, 2010, 12:00:00

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().


More From » jquery

 Answers
56

This should work:



$(#+$(this).attr(id)+ :selected)


it's not pretty but it does the trick :)



or this will work:



$(this).find(:selected).text()

[#95577] Thursday, September 16, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elliem

Total Points: 415
Total Questions: 117
Total Answers: 94

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
;