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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:06:43+00:00 2026-05-18T12:06:43+00:00

I am working on an e-commerce application shopping cart. I have a pricing page

  • 0

I am working on an e-commerce application shopping cart. I have a pricing page which display a list of products and their prices for multiple categories. User can choose to add multiple products to shopping cart (active shopping cart is being shown on right hand side of page). I am trying to use Ajax/jQuery for adding items to my cart. I have a form wrapped around each product which contains multiple hidden fields I would like to pass to my function and to the controller. You can see all these in the code below:

<% foreach (var _category in Model) { %>
    <% foreach (var _product in _category.Products)
        { %>
        <tr>
            <td align="left" valign="top"><% = _product.Description %> (<% = _product.Code %>)</td>
            <td valign="top" align="center">$<% = _product.TotalPrice %></td>
            <td align="left">
                <form id="frmProduct_<%=_product.Code%>">
                    <input type="button" onclick="JavaScript:addProductToBasket(this.form);" value="+ Add to cart" />
                    <input type="text" id="hProductCode" value="<% = _product.Code %>" />
                    <input type="text" id="Text1" value="<% = _product.TotalPrice %>" />
                    <!--Other hidden fields for passing data -->
                </form>
            </td>
        </tr>
    <% } %>    
<% } %>    

Since I have multiple forms on page, I am having hard time accessing a particular form inside my javascript function. What is a best way to handle this scenario?

<script type="text/javascript">
    function addProductToBasket(_form) {
        alert('Hi');
        var str = $('#_form').serialize();
        alert(str);
    }
</script>

I am using ASP.NET MVC 2.0 and cannot move to MVC 3.0 at the moment.

  • 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-05-18T12:06:43+00:00Added an answer on May 18, 2026 at 12:06 pm

    Try to make your forms working without using javascript first. Then start thinking about all the ajax and jQuery stuff.

    • Remove the id attribute from the forms and add an action attribute (or use the MVC method: Using Html.BeginForm), add a class attribute to the form tag.
    • Remove the Totalprice field, you should always calculate this server-side, the only fields you need to submit are the product code (and a quantity).
    • Remove the javascript button and replace it with a classic submit button.

    When you want to ajaxify the form, try something like this:

    $(function () {
     $(".addproductform").submit(function () { // turn all forms with the addproductform class into an ajax version
      $.post($(this).attr("action"), $(this).serialize(), function (data) {
       // data contains the confirmation or failure that the product was added to your cart, update the cart html on this page
      });
    
      return false; // form already submitted using ajax, don't submit it again the regular way
     });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a database for an e-commerce application, we are working with JPA 2.0.
I'm working on a site using the Big Commerce platform. The cart page is
I'm working on a database design for an e-commerce web application. For this question
I am working an e-commerce site which will allow pdfs to be downloaded once
I'm working at some e-commerce website where I have a bunch of filters for
I'm working through some touches on an e-commerce site for someone and have run
I'm learning C# and working on my first ASP.Net e-commerce website. I have the
I'm working on an e-commerce type web application and need to somehow handle calculation
I have created dynamic pricing forms within a e-commerce site using javascript and it
I have an accordion menu working on the page, but when I click one

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.