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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:09:56+00:00 2026-06-06T23:09:56+00:00

I am trying to take an <option> variable so that I can use it

  • 0

I am trying to take an <option> variable so that I can use it to calculate the total price of a product.

E.g. The <option> is the quantity of an item. I need that to multiply with the price to get the total. The total will be displayed on the same page as the dropdown. How do I assign a variable to the select option?

<?php 
    if ($product->quantity < $product->max) $q = $product->quantity;
    if ($product->quantity > $product->max) $q = $prodcut->max;
    if ($product->quantity = $product->max) $q = $product->max;

    for($i=1; $i<=$q; $i++){ 
        echo '<option value="'.$i.'">'.$i.'</option><br/>';
    }
?> 
  • 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-06T23:10:00+00:00Added an answer on June 6, 2026 at 11:10 pm

    If I understand you correctly you want to be able to dynamically show a sub total of items on the page?

    The best way to do this is to use javascript (jQuery). Once the page is rendered on your browser it is no longer being run server-side. PHP is a server side programming language and therefore cannot run once the HTML has been delivered to the browser.

    There are two ways around this. You can use ajax (linked to jQuery’s ajax function) to send the option value via javascript to a php script which will calculate the price and send it back.

    However, as its a pretty simple calculation that doesn’t require server side programming, it might be better just to do it all client side. E.g. in jQuery

    jQuery(document).ready(function($){
        $('select#qty').change(function(){
            var price = parseFloat($('input#price').val()); // hidden input with price in it
            var qty = parseInt($('select#qty').val()); // option selected with qty
            var total = price * qty; // calculate total
            $('div#total').text(total); // update the div showing the total
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use rsync to take backup of a rapidly changing directory
I am trying to write some javascript that will automatically take text in a
We're trying to use Jackson 1.5 to take advantage of some of the polymorphic
I'm trying to get the ActionView-Helper collection_select to take a value that will be
I'm trying to take all the elements within a particular and capture the option
I am trying to find a way to take an array of keywords that
I am trying to create a drop down list that would take me to
I have a datagridview with 9 columns. I am simply trying take the value
trying to take this content: <div class=content>one,two,three</div> <div class=content>four,five,six</div> <div class=content>seven,eight,nine</div> and .split and
Im trying to take a link either when clicked or hover over be able

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.