$('this option:selected') is looking for a DOM element of <this></this>
it needs to be $(this).find('option:selected') On Jan 27, 3:12 pm, "Rick Faircloth" <r...@whitestonemedia.com> wrote: > Hi, all... > > Are the first three lines of code below legitimate? > I've got a page full of dropdowns (.agents) and when > a user uses one to change the agent, I want to send > the choice to my processing page via ajax. > > I want to trigger the ajax function when the user > changes the selection and I saw in the docs where > the option selection could be used to do that, so I tried > to modify the code to suit my needs. > > Apparently, I've got something wrong, because I get > no response from changing the dropdown. No errors > in Firebug, either. > > The first three lines of code are of concern and also > the use of "this" to specify the agent_id in the "formval" var. > > Will those code work, if modified, or should I > just go with changing the dropdown and then giving the user > an update button to trigger the ajax function? > > Thanks for any feedback. > > Rick > > <script> > > $(document).ready(function() { > > $('.agents').change(function() { > > $('this option:selected').each(function() { > > var formval = { dsn: > '<cfoutput>#application.dsn#</cfoutput>', > agent_id: $(this).attr('value') }; > > $.ajax({ cache: false, > type: "POST", > url: > "../components/floor_duty.cfc?method=get_new_agent&returnFormat=json", > dataType: "json", > data: formval, > success: function(response) { > > if (response.MESSAGE == > 'Success') > > { alert('Success'); } > > else > > { alert('Failure'); } > > } > > }); > }); > > }); > > });