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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:31:28+00:00 2026-06-08T02:31:28+00:00

I have 2 drop down boxes to select products and a div for a

  • 0

I have 2 drop down boxes to select products and a div for a shopping cart.

<select id="RAM">
  <option value="1">4 GB</option>
  <option value="2">8 GB</option>
</select>

<select id="HDD">
  <option value="1">300 GB</option>
  <option value="2">500 GB</option>
</select>

<ul id="cart">
  <li>PRODUCT NAME (PRICE)</li>
  <li>PRODUCT NAME (PRICE)</li>
</ul>

and I want to pass this dropdown value to a PHP file using AJAX and return product name & Product price etc, to #cart as a <li> with out refreshing page. and also without repeating the same product. Please suggest me a good/secure way to do this.

  • Client can always change what he choose Ex: 4 GB RAM to a 8GB RAM.
  • 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-08T02:31:30+00:00Added an answer on June 8, 2026 at 2:31 am

    Firstly, create form:

    <form id="form">
      <select name="RAM">
        <option value="0">4 GB</option>
        <option value="1">8 GB</option>
      </select>
    
      <select name="HDD">
        <option value="0">300 GB</option>
        <option value="1">500 GB</option>
      </select>
    </form>
    
    <ul id="cart">
      <li>PRODUCT NAME (PRICE)</li>
      <li>PRODUCT NAME (PRICE)</li>
    </ul>
    

    And ajax code (I use jQuery library because of its compatibility with all browsers):

    $(document).ready(function() {
            $('#form').change(function() {
                $.ajax({
                    url: 'script.php',
                    type: 'post',
                    data: $(this).serialize(),
                    dataType: 'json',
                    success: function(data) {
                        $('#cart').empty();
                        $.each(data, function(index, value) {
                            var $li = $('<li></li>')
                                .text(value['product'] + ' (price: ' + value['price'] + ')')
                                .appendTo($('#cart'));
                        });
                    }
                });
            });
        });
    

    Now you have to write PHP script:

    <?php
    
    $prices = array(
        'HDD' => array(30, 50),
        'RAM' => array(100, 200)
    );
    
    $data = array();
    foreach ($_POST as $product => $index)
        $data[] = array('product' => $product, 'price' => $prices[$product][$index]);
    
    print json_encode($data);
    exit;
    

    I think you want to save users choices. If I’m right, add saving products to cookies or database.
    Cookie example:

    setcookie('cart',$data,time()+24*3600*5,'/'); // save cookie for 5 days
    

    I hope it is useful for you 🙂

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

Sidebar

Related Questions

I have 4 different select boxes (to select one option from drop down). All
I have two drop down boxes in my program. When you select an item
I have a form with two text boxes, one select drop down and one
I have 3 drop down boxes, created using the HTML select tag. On page
I have 3 drop down (combo boxes) or select lists on a page. It
Hi I have problem with IE9. I have drop down menu with select boxes
I have some drop-down boxes that act as filters on a page. When either
In my application i have two drop down boxes first box had origin second
how to fill text boxes based on drop down selection i have a table:
I have a drop down menu. Has product types. Product types have associated value

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.