Doesn't 'this' point to the DOM object in question in JS? I think
this is somewhat what you're looking for, but perhaps I'm
misunderstanding (you did post about it four times though, so I should
understand :p):
$("#your_select_id").live("change",function(event){
// this is the object(s) you bound to; might need to use $
(this).each(function() {...}) to operate on the right form?
$(this);
// And you can find the form its on like this
$form = $(this).parents('form');
// And these are the params for your form
var params = $.param($form.serializeArray());
// Add in authentication token if applicable
params += '&authenticity_token=' + encodeURIComponent(...);
// And submit something like this
$.ajax({
data: params,
type: 'post',
url: '/some_post_back'
});
}
Or am I still misunderstanding?
On Mar 4, 12:01 pm, lunaclaire <[email protected]> wrote:
> I did take the first steps in switching to jQuery by using jRails, but
> now I'm trying to "do the right thing" and start moving this app away
> from the obtrusive JS and those helpers. I've been using
> remote_function for a long time, but using the conversion here as a
> model for how to move behaviors to the application.js and away from
> the views themselves.
>
> So, if someone can answer the question 2 posts back about how to
> generate/pass the params that should help me "get it" as far as how to
> set those behaviors up.
>
> The conceptual prob I'm having is that the way I've been doing it
> seems to have a tighter coupling betw the obj being displayed and the
> need in some cases (like this one) to pass info about that obj back to
> the controller.
>
> It seems that by having the jQuery code "waiting" for an event
> (onChange here), it's decoupled from the view and, thus, doesnt know
> as much about obj's and such associated with the element it's
> responding on.
>
> So, my question remains... how to pass/access relevant values for the
> behavioral response?
>
> On Mar 4, 7:17 am, Peter <[email protected]> wrote:
>
> > Easiest thing to do is to make a simple remote_form_for/
> > form_remote_tag and look at the jQuery it produces in its onsubmit
> > function. However, I'm a little confused, why not just put your
> > select box inside a form tag that posts to your URL and let rails
> > helpers + jrails do the parameter scrapping and submission for you?
>
> > On Mar 4, 1:31 am, lunaclaire <[email protected]> wrote:
>
> > > Thx, Amar.
>
> > > I should have been more clear... My need for answers stems from my
> > > ignorance of how to access values known in a view to JS and the jquery
> > > code so that they can be accessed there or posted back to the server
> > > thru ajax.
>
> > > curr the remote_function() call has the url params which are known in
> > > my view (the action to post to and the obj ID of interest that the
> > > selection is for), but I cant figure out how to generate that url in
> > > JS/jQuery
>
> > > I think I've done this kind of thing before, but I'm missing it at the
> > > moment.
>
> > > Can someone show me?
>
> > > On Mar 3, 9:34 pm, Amar Daxini <[email protected]> wrote:
>
> > > > lunaclaire wrote:
> > > > > II'm switching to jQuery and wondering how do I pull the onchange:
> > > > > stuff out of the following for a select and put it into a handler?
>
> > > > > here's what I have in my view now:
>
> > > > > <%= select_tag :selected_email,
> > > > > options_from_collection_for_select(update_request.contact.emails,
> > > > > 'id', 'value', update_request.contact.primary_email_id),
> > > > > :onchange => remote_function(:url => {:action
> > > > > => :set_request_email, :id => update_request.id}, :with => "'value=' +
> > > > > value"),
> > > > > :id => "request_email_#{update_request.id}" %>
>
> > > > $("#your_select_id").live("change",function(event){
> > > > //It return whatever value is selected
> > > > value_of_select =$("#your_select_id").val();
> > > > //Now call ajax request on change
> > > > //You can refer codehttp://railstech.com/?p=58});
>
> > > > Refer Codehttp://railstech.com/?p=58
> > > > --
> > > > Posted viahttp://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.