Dummy me... I had the select input named "agents",
but was referring in the jQuery to what I thought was
its class ".agents". Now that the class has been assigned
as .agents, all is working.
Thanks, guys, sorry for the silly mistake!
Rick
> -----Original Message-----
> From: jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.com] On Behalf Of Rick Faircloth
> Sent: Tuesday, January 27, 2009 4:08 PM
> To: jquery-en@googlegroups.com
> Subject: [jQuery] Re: This code, no response...will this work, if modified?
>
>
> Thanks for the feedback, MorningZ and Eric.
>
> I've tried both your suggested changes for this line:
>
> I tried:
>
> $(this).find('option:selected').each(function() {
> and
> $('option:selected', this).each(function() {
>
> but nothing's working.
>
> I also tried re-writing it according to your suggestion, Eric,
> (see below), but that didn't work...no error messages, but
> no response at all.
>
> How could I use console.log (or something else) to troubleshoot this?
>
> Thanks for your help, both of you!
>
> Rick
>
>
> $(document).ready(function() {
>
> $(function() {
>
> var agent_data = { dsn: '<cfoutput>#application.dsn#</cfoutput>',
> method: 'get_new_agent',
> returnFormat: 'json',
> agent_id: null };
>
> $('.agents').change(function() {
> $('option:selected', this).each(function() {
> agent_data.agent_id = $(this).val();
>
> $.post('../components/floor_duty.cfc?', agent_data, function() {
>
> alert( response.MESSAGE == 'Success' ? 'Success' : 'Failure' );
>
> }), 'json'
> });
>
> });
> })
> });
>
> > -----Original Message-----
> > From: jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.com] On Behalf Of Eric Garside
> > Sent: Tuesday, January 27, 2009 3:27 PM
> > To: jQuery (English)
> > Subject: [jQuery] Re: This code, no response...will this work, if modified?
> >
> >
> > $('this option:selected').each(function() {
> >
> > Should be changed to
> >
> > $('option:selected', this).each(function() {
> >
> > That's the only glaring error I saw with it. Though you could probably
> > clean it up a bit:
> >
> > $(function(){
> > var agent_data = {dsn: '<cfoutput>#application.dsn#</cofoutput>',
> > method: 'get_new_agent', returnFormat: 'json', agent_id: null};
> > $('.agents').change(function(){
> > $('option:selected', this).each(function(){
> > agent_data.agent_id = $(this).val();
> > $.post('../components/floor_duty.cfc?', agent_data, function()
> > {
> > alert( response.MESSAGE == 'Success' ? 'Success' :
> > 'Failure' );
> > }), 'json');
> > });
> > })
> > });
> >
> > 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'); }
> > >
> > > }
> > >
> > > });
> > > });
> > >
> > > });
> > >
> > > });
No comments:
Post a Comment