views:

32

answers:

2

Hi

I'm trying to pass a string with a link_to_remote call as the :id, and the string should be collected from an input field with and id of "movie_title".

<div id="search_list">Nothing here yet</div>
<br />

<% semantic_form_for @movie do |f| %>
    <% f.inputs do -%>
        <%= f.input :title, :class => "movie_title" %> <%= link_to_remote( 'Search...', { :url => { :action => :imdb_search, :id => "'+$('\#movie_title').value+'" } }, { :title => "Search for this movie", :class => "imdb_search" } ) -%>
        [...removed text that does not matter...]
    <% end -%>
    <%= f.buttons %>
<% end %>

I keep getting an javascript error, and if I remove the # from the jquery in the link, it returns "Undefined".

The link I get is:

<a class="imdb_search" href="#" onclick="jQuery.ajax({data:'authenticity_token=' + encodeURIComponent('yHPHYTZsPTQLi9JYSauUYcoie/pqPPk2uHBTN0PzNsQ='), dataType:'script', type:'post', url:'/movies/imdb_search/'+$('%23movie_title').value+''}); return false;" title="Search for this movie">Search...</a>

So I want the link updated with the contents of movie_title. How do I do that?

A: 

I'd try something like

<%= link_to_remote( 'Search...', { 
   :url => { :action => :imdb_search},
   :with => "'id=' + $('movie_title').value",
   {:title => "Search for this movie", :class => "imdb_search"}
)
j.
Just made this. Gives me movie=>undefined[code]<%= link_to_remote( 'Search...', { :url => { :action => :imdb_search, :id => "'+$('movie_title').value+'" }, :with => "'movie=' + $('movie_title').value" }, { :title => "Search for this movie", :class => "imdb_search" } ) -%>[/code]Sorry, don't know how to format in the comments...
cmol
A: 

Fixed it

Used:

$('movie_title').val()

Insted of

$('movie_title').value
cmol