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 8634881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:49:49+00:00 2026-06-12T09:49:49+00:00

This is a slightly tricky question to put into words. Basically I’ve been trying

  • 0

This is a slightly tricky question to put into words. Basically I’ve been trying to build a shopping cart page in KnockoutJS based on one of the examples in the the KnockoutJS website (http://knockoutjs.com/examples/cartEditor.html). However I wanted to make use of jQueryUI sliders so that I could adjust the values of each product in my cart.

This I’ve managed to get working OK and I can add a product (in this case Motorcars) to my basket and adjust the value and also increase/decrease the value depending on whether the car has a sports kit or is a convertible.

http://jsfiddle.net/FloatLeft/UjRrJ/

However, instead of adding a product (the “Add Car” button) and then choosing the car type, I want to be able to add a specific type (eg BMW, Ford) to the cart at the click of the button (eg clicking on the “Add BMW” button – this does nothing at the moment).

However my simple brain cant work out how to bind the button to a specific car in the collection. I think I can retrieve the car by creating a function that iterates over the collection and finds the car that has the type that matches a string, e.g.

    function GetCar(carType) {
        for (var i = 0; i < sampleCars.length; i++) {
            if (sampleCars[i].Type == carType) {
                return sampleCars[i];
            }
        }
    }

So basically I want to know how I can bind the click event of “Add BMW” button to a particular car in the collection and have that added to my cart.

  • 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-12T09:49:50+00:00Added an answer on June 12, 2026 at 9:49 am

    If you plan on making multiple buttons, you can create a function which can create your event handlers which can take in a car type.

    self.addSpecificCarLine = function (carType) {
        return function () {
            var car = ko.utils.arrayFirst(sampleCars, function (car) {
                return car.Type === carType;
            });
            var cartLine = new CartLine();
            cartLine.car(car);
            self.lines.push(cartLine);
        };
    };
    

    Then you can bind to the handlers like so:

    <button data-bind='click: addSpecificCarLine("BMW")'>Add BMW</button>
    

    Updated fiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a slightly tricky question. I am using NSDateFormatter on the iPhone but
I know this question has been done but I have a slightly different twist
This question has been asked in various guises. However. this is a slightly different
Apologies if this is a slightly noob question, but looking to clarify my thoughts
OK, this is a slightly weird question. We have a touch-screen application (i.e., no
I have a question which is slightly similar to this question on stackoverflow std::cin.clear()
I'm trying to style up this heading. It slightly pops out the side with
A slightly tricky SQL question (we are running SQL server 2000). I have the
I've got a slightly tricky problem to solve; imagine this: One of my applications
Please try to forgive this slightly off-programming-topic question. At least I'm getting this problem

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.