Jump to content

Quote/Estimate


Alex L

Recommended Posts

Hi, I've tried to find a solution for this but I've had no luck. I don't really mind how it works as long as it gets the job done.

 

So, what I've tried to do is make a system which estimates the price of something and then emails the information.

 

So, say I have a dropdown menu with two options, one which is £10, one which is £20, I want the estimated value to change depending on what is selected.

 

Is there a way to do this, eaither on the page or as a separate page called quote.php or something like that.

 

My current code is below.

 

 

      <form method="post" action="sendmail.php">
    <div id="left">
      <p><b>Name:</b><br /><input type="text" name="name" /></p>
      <p><b>Daytime Number:</b><br /><input type="text" name="daytime" /></p>
      <p><b>Address Line 1:</b><br /><input type="text" name="address1" /></p>
      <p><b>City/Town:</b><br /><input type="text" name="citytown" /></p>
      <p><b>Postcode:</b><br /><input type="text" name="postcode" /></p>
      <p><b>Cake Type:</b><br /><select name="caketype">
        <option>Fruit cake +£0<?php $caketype=0; ?></option>
        <option>Sponge +£20<?php $caketype=20; ?></option>
        <option>Chocolate +£30<?php $caketype=30; ?></option>
      </select></p>
      <p><b>Tiers:</b><br /><select name="tiers">
        <option>1 Tier +£0<?php $tiers=0; ?></option>
        <option>2 Tiers +£20<?php $tiers=20; ?></option>
        <option>3 Tiers +£40<?php $tiers=40; ?></option>
        <option>4 Tiers +£60<?php $tiers=60; ?></option>             
        <option>5 Tiers +£80<?php $tiers=80; ?></option>
        <option>6 Tiers +£100<?php $tiers=100; ?></option>
      </select></p>
      <?php $base = 100; $quote=($base+$caketype+$tiers+$decorativebox);?><h4>Estimated Price: £<?php echo $quote; ?></h4>
      <p><input type="submit" value="Submit Message"/><input type="reset" /></p>
    </div>

    <div id="right">
      <p><b>Email:</b><br /><input type="text" name="email" /></p>
      <p><b>Mobile Number:</b><br /><input type="text" name="mobile" /></p>
      <p><b>Address Line 2:</b><br /><input type="text" name="address2" /></p>
      <p><b>County:</b><br /><input type="text" name="county" /></p>
      <p><b>Message:</b><br /><textarea name="message" cols=30 rows=3></textarea></p>
      <p><b>Extras:</b><br />
         <input type="checkbox" name="decorativebox" value="decorativebox"<?php if (isset($_POST['decorativebox']))
{$decorativebox = 25;} else {$decorativebox = 0;} ?>/>Decorative Box +£25<br />
         <input type="checkbox" name="checkbox" value="Test 2" />Test 2<br />
         <input type="checkbox" name="checkbox" value="Test 3" />Test 3<br />
         <input type="checkbox" name="checkbox" value="Test 4" />Test 4<br />
         <input type="checkbox" name="checkbox" value="Test 5" />Test 5</p>
      <br />      
    </div>
      </form>

 

Thanks to anyone that can help.

Link to comment
Share on other sites

Sorry, I don't understand what to do and I'm not using a database, I was trying to do it without having to.

 

I'm not 100% sure what you wish to do. Do you want the estimate to be added upon 10 pounds if it goes up from 10->20 in the selection box?

 

Wherever your actions are to take the POST data from the selection box, you may want to add it into a session variable (if you can not create a session, look for a tutorial, it's simple). Once you submit the form it'll simply be like.. $_SESSION['estimate_total'] += 10;.. So you can echo it like "Your estimate cost is ". $_SESSION['estimate_total'] . "pounds".

 

EDIT: If you want it to be automatic (I.E.: Not refreshing the page) You'll need to use AJAX to query quote.php and fill in the value..

Link to comment
Share on other sites

This would be better done as a javascript update based on the values of the dropdowns

I dont think you understand the difference between a server side script and a client side script. client side is what you want, and PHP is server side. Use javascript to do the dropdown quote, then parse the values from the form using php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.