Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7932349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:59:23+00:00 2026-06-03T20:59:23+00:00

All i want to do in simple words: When input value is changed, i’ll

  • 0

All i want to do in simple words: When input value is changed, i’ll put this value in db.
I want to add some ajax. I want to do this:
When I change my input value (focusout), i call some method, using get-parametr, my method looks like this:

def update_quantity
    @cart = current_cart
    @line_item = LineItem.find(params[:id])
    respond_to do |format|
      if @line_item.update_attribute(:quantity, params[:quantity]) #&& @cart.id == params[:cart]
        format.html { redirect_to(@line_item, :notice => 'Line item was successfully updated.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @line_item.errors, :status => :unprocessable_entity }
      end
    end
  end

This is test-work, so it maybe have some bad solutions, and my view looks like this:

%p
    = line_item.art_name
    = line_item.ART_ID
    = line_item.art_code
    &times
    .cart-quantity
        = line_item.quantity        
        %input{ :class => "quantity", :value => line_item.quantity }
        = link_to "обновить", :controller => "line_items", :action => "update_quantity", :id => line_item.id, :quantity => line_item.quantity, :cart => @cart.id    
    = line_item.total_price

As you see, I want to: when input focus is out, i get new hidden link, and call it, which calls method, which is written upper.
What i need to do? what files to create and where, and how to do this? Wanna some ajax)

All i want to do in simple words: When input value is changed, i’ll put this value in db.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:59:24+00:00Added an answer on June 3, 2026 at 8:59 pm

    You don’t need a hidden link to accomplish this. Use the onblur field of the html element:

    :javascript
      function updateQuantity() {
        $.ajax({
           url: "/line_items/update_quantity",
           type: "POST",
           data: {id: $(this).attr('id'), quantity: $(this).attr('quantity'), cart: $(this).attr('cart_id')} 
        })
      }
    
    %input.quantity{:value => line_item.quantity, :onblur => updateQuantity(); :id => line_item.id, :quantity => line_item.quantity, :cart => @cart.id}
    

    In this example I inlined the javascript, it should really go in your application.js document.ready() block

    $(document).ready(function() {
      $(".quantity").onfocusout(function() {
         $.ajax({
               url: "/line_items/update_quantity",
               type: "POST",
               data: {id: $(this).attr('id'), quantity: $(this).attr('quantity'), cart: $(this).attr('cart_id')} 
            })
      })
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can't seem to achieve this simple functionality! All I want is to clear a
This is probably pretty simple. I want to select all elements of a given
ok all I want to do is give the user a simple form where
I have a very simple jQuery script.. all I want it to do is
I have created a very simple sharepoint timer job. All i want it to
i want to create a simple state machine using C but all the events
Very simple Winforms application I want to deploy manually. Can all the referenced assemblies
I learning Perl and I want to create a simple application that gets all
I.e., I get a list of words and I want to construct a simple
simple question: I have input fields with inside-labels! Just like the search-box on this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.