rail ajax remote form to update text field upon submission

All I want to do is update a text field on my page with a value when my Rails remote form is submitted.

All the source code be found at github here https://github.com/iamliamnorton/fasdac

The form is on the index page...

Controller code...

def index

  @calculator = Calculator.new(params[:calculator])
  if @calculator.valid?
    respond_to do |format|
      format.html { redirect_to calculator_path(:calculator => params[:calculator]), :notice => 'Calculation was successfully completed.' }
      format.js
    end
  else
    respond_to do |format|
      format.html { redirect_to calculator_path(:calculator => params[:calculator]), :alert => "Calculation was not successfully completed. #{@calculator.errors.full_messages.to_sentence}" }
      format.js
    end
  end

My input form

<%= form_for(@calculator, :url => calculator_path, :remote => true) do |f| %>
...
<% end %>

And the index.js.erb

$("#result").value = "SUCCESS!";

I'm trying to update a input text field with name and id 'result'. I cannot get this working, I've tried many different variants in the index.js.erb but cannot get it working. What am I doing wrong?

It looks like the data is being sent to the controller as I can see in the server console

...
Processing by CalculatorController#index as JS
...

But I can't get the text area to update

Answers


index.js.erb

$('#result').val("Success!");

Need Your Help

Python int(90.0) = 89 error

python int

This is a glitch in a larger program I wrote that I can't figure out. I'm using Python 2.7.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.