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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:14:35+00:00 2026-05-23T00:14:35+00:00

I have created dynamic pricing forms within a e-commerce site using javascript and it

  • 0

I have created dynamic pricing forms within a e-commerce site using javascript and it works fine. However I would prefer my more complex pricing computations to be in a PHP file external to the HTML form.
The calculations are fairly complex and I have got them all working using PHP however I am new to PHP and for the life of me cant figure out how to get the result of the calculations to be returned to the html form. The user can then “Add to Cart”

Here are very simple examples to try and explain

HTML form

<html> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>demoform</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="myform.php">
<label>Width<input type="text" name="width" id="width" size="6"></label><p>
<label>Length<input type="text" name="length" id="length" size="6" ></label><p>
<label>Price $</label> <input id="Price" readOnly size=6 name=Price><p>
<label for=otherprice></label><input id="otherprice" readOnly size=6  type=hidden 
name=otherprice><p>
<input type="submit" name="submit" id="submit" value="Get Price" ><p>
<input id="addtocart" title="Add to Cart" onclick="return validate(this.form)" value="Add to Cart" type="submit" ?>
</form>
</body>
</html> 

PHP File

<?php

$width=$_POST['width'];
$length=$_POST['length'];
$Area = $width*$length;
$total = $Area * .01;
$price = round($total * 100) / 100;
$otherprice = round($price * 1.2 * 100)/100 ;

?>

<?php echo "$price"?><br/>
<?php echo "$otherprice"?>

Instead of a new page opening is it possible
for $price to be input into the HTML price field
and for $otherprice to be input into the HTML otherprice (hidden) field within the demoform.html page

John

  • 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-23T00:14:36+00:00Added an answer on May 23, 2026 at 12:14 am

    PHP script:

    <?php
    $width =$_GET['width'];
    $length = $_GET['length'];
    $area = $width * $length;
    $total = $area * .01;
    $price = round($total * 100) / 100;
    $otherprice = round($price * 1.2 * 100) / 100;
    
    echo json_encode(array($price, $otherprice));
    ?>
    

    JavaScript:

    function Ajax() {
        this.instance = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
        this.request = function(url, callback) {
            this.instance.open('GET', url, true);
            this.instance.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    callback(this.responseText);
                }
            }
            this.instance.send(null);
        }
    }
    function validate(form) {
        (new Ajax).request('prices.php?width=' + form.width.value + '&length=' + form.length.value, function(respons) {
            var prices = eval(respons);
            form.price.value = prices[0];
            form.otherprice.value = prices[1];
        });
    }
    

    The Ajax class is something that I created. You are free to use it or not. You can also do it without the class. I usually do it this way because it’s easy to make multiple XHR objects.

    HTML:

    <form name="form1" method="post" action="myform.php">
        <p>
            <label>Width <input type="text" name="width" size="6" /></label><br />
            <label>Length <input type="text" name="length" size="6" ></label><br />
            <label>Price <input type="text" name="price" readonly="readonly" size="6" /></label>
            <input type="hidden" name="otherprice" readonly="readonly" size="6" /><br />
            <input type="button" value="Get Price" onclick="validate(this.form)" />
        </p>
        <p>
            <input type="submit" value="Add to Cart" />
        </p>
    </form>
    

    Also please clean up your HTML. 🙂

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

Sidebar

Related Questions

I have created a dynamic list picker script using Jquery 1.3 and PHP that
I have created a Dynamic Data site against an Entity Framework Model I have
I have created my dynamic web project in Eclipse. Since my UI use javascript
I have created one dynamic query and it all works well. I execute the
I have created a composite component in JSF2. I works great. I would like
I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a C# class file by using a XSD-file as an input.
i have created dynamic button with code below, the button caption is too long
I have created a Dynamic Web Project in my Eclipse workspace. It is also
I have created a dynamic typing system in C in order to create a

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.