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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:47:58+00:00 2026-05-12T06:47:58+00:00

I’m trying to update the value of a field based on a select box

  • 0

I’m trying to update the value of a field based on a select box select option and the quantity of few quantity fields, it works fine for the first field but it wouldn’t work for the rest.

this is the link to the site is http://www.snappy-pizza.net/pizza1c.php

if you choose a pizza for the first time and add toppings to it, the value of the updated price field will increase as expected, now if you change your pizza with the same toppings only the first topping will be added to the price and not the other ones.

  <input name="update_price" type="text" id="update_price" value="" size="8" maxlength="8" />


  <form>
                <select name="select" id="select">
                  <option>Select your pizza</option>
                  <option value="6.65">NY, 10&quot;, £6.65</option>
                  <option value="8.95">NY, 12&quot;, £8.95</option>
                  <option value="11.95">NY, 16&quot;, £11.95</option>
                  <option value="3.45">Chicago, 7&quot;, £3.45</option>
                  <option value="6.65">Chicago, 10&quot;, £6.65</option>
                  <option value="8.95">Chicago, 12&quot;, £8.95</option>
                  <option value="11.95">Chicago, 16&quot;, £11.95</option>
                  <option value="19.95">Chicago, Beast 24&quot; x 18&quot;, £19.95</option>
                 </select>
         </form>


       <form>
         <tr>
            <td> 

            <span class="descriptionsPizza">EXTRA CHEESE</span>
            <input name="minus1" type="button" class="button minus" id="minus1" value=" - " />
            <input name="textfield1" type="text" id="textfield1" class="valfield" size="2" maxlength="2" value="0" />
            <input name="add1" type="button" class="button add" id="add1" value=" + " />
            </td>

            <td>
            <span class="descriptionsPizza">HAM</span>    
            <input name="minus2" type="button" class="button minus" id="minus2" value=" - " />
            <input class="valfield" name="textfield2" type="text" id="textfield2" size="2" maxlength="2" value="0"/>
            <input name="add2" type="button" class="button add" id="add2" value=" + " />
            </td>
            </tr>




           //function to change the quantity field by pressing the + and - buttons
   $(function()
    {
      topping_price = 1;
      $(".add").click(function(){
     var newQty =+($(this).siblings(".valfield").val()) + 1;
     $(this).siblings(".valfield").val(newQty);

 current_price =+($('input[name=update_price]').val() );
 $('input[name=update_price]').val(topping_price + current_price);
  });

 $(".minus").click(function(){
 var newQty = +($(this).siblings(".valfield").val()) - 1;
 if(newQty < 0)newQty = 0;
 $(this).siblings(".valfield").val(newQty);

var current_price =+($('input[name=update_price]').val() );
$('input[name=update_price]').val(current_price - topping_price);
});

});

  //function to get the value and text of the selected select box and insert them into hidden fields.
 $(function()
  {
$('#select').change( function() {
    $('input[name=my-item-name]').val( $("#select :selected").text() );
    $('input[name=my-item-price]').val( $("#select").val() );

    $(".add").each(function() {
        //gets the value of the selected box (i.e.price) and insert it into the updated price field.
        var new_qty =+ ($(".add").siblings(".valfield").val() );
        var pizza_price =+ ($("#select :selected").val() );
        $('input[name=update_price]').val((new_qty * topping_price) + pizza_price);
    });
});

});

any help would be appreciated..

  • 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-12T06:47:58+00:00Added an answer on May 12, 2026 at 6:47 am

    I have improved your jquery.js file. This version is much cleaner.

    // JavaScript Document
    
    var toppingPrice = 1;
    
    //function to get the value and text of the selected select box and insert them into hidden fields.  
    var updateTotalPrice = function() {
      var pizzaPrice = parseFloat($("#select").val());
      var quantity = 0;
      $(".add").each(function() {
        quantity = quantity + parseInt($(this).siblings(".valfield").val(), 10);
      });
      $('#update_price').val((quantity * toppingPrice) + pizzaPrice);
    }
    
    $(function()
    {
      //functions to change the quantity field by pressing the + and - buttons
      // add buttons
      $(".add").click(function(){
        var $this = $(this);
        var quantity = parseInt($this.siblings(".valfield").val(), 10) + 1;
        $(this).siblings(".valfield").val(quantity);
    
        updateTotalPrice();
      });
    
      // minus buttons
      $(".minus").click(function(){
        var $this = $(this);
        var quantity = parseInt($this.siblings(".valfield").val(), 10) - 1;
        if(quantity < 0) quantity = 0;
        $(this).siblings(".valfield").val(quantity);
    
        updateTotalPrice();
      });
    
      // selectbox
      $('#select').change(function() {
        updateTotalPrice();
      });
    
      //function to generate a random number and insert them to the item id hidden field
      $('input[name=my-add-button]').click(function() {
        var randomNumber = Math.floor((Math.random() * 9000) + 100);
        $('input[name=my-item-id]').val(randomNumber);
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.