$("#[$.variables.formID]") - that is a plain string, and there is no
need for the brackets. You probably meant to use

$("#"+$.variables.formID).append(...)

But it's much easier to save the current form itself, instead of it's
ID:

$('[id^=credit]').change(function() {
   var $self = $(this);
  $.ajax({
     type: "POST",
     url: "/credits/edit",
     data: $self.serialize(),
     beforeSend: function(){
        $self.append("<div>YAY</div>");
    },
    success: function(html) {
       //...
    } //make sure you don't have a comma after the last object, syntax
error
  })

On Jan 31, 5:32 am, frodosghost <jamesmon...@gmail.com> wrote:
> Howdy Guys,
> A bit of a problem I have been struggling with for a number of hours,
> and some help would go a long way.
>
> Its not really a problem with the $.ajax() function. It is more a
> problem with selecting live variables on the fly. I have multiple
> forms on one page, so selecting that one form to use and update data
> is what I am looking at doing.
>
> $.variables = {}; //Sets up an array so I can call the vars in which
> ever function I'd like to.
>
> $('[id^=credit]').change(function() {
>   $.variables = {formID : $(this).attr('id')}; // Meant to pass the
> id, but passes an object.
>   $.ajax({
>     type: "POST",
>     url: "/credits/edit",
>     data: $(this).serialize(),
>     beforeSend: function(){
>       $("#[$.variables.formID]").append("YAY"); //Just to put
> something in this form id.
>       console.log($( [$.variables.formID] )); // Returns this in the
> console: Object length=1 0=credit1 jquery=1.3.1
>     },
>     success: function(html) {},
>   })
>
> So I have set the variable.formID after the .change function. It
> passes an object, but I am looking at passing the actual id, so that I
> can put some data into that form id...
>
> If I use this $("#[$.variables.formID][0]").append("YAY"); code in the
> first line of the before send (in an effort to get to the [0] in the
> object it passes, it updates all forms on the page with the .append.
> But it only sends the data from that one form.
>
> Because there is a number of forms on this one page, I'd just like to
> be able to select the id for the form, so I can update data in that
> form - At this stage I can get data into any form with an ID, but not
> the form that has been used.
>
> Am I missing something? I could have completely stuffed up how to do
> it. Any tips would be welcome.
>
> Thanks

Reply via email to