[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

Automatic Calculation Script

I basically want a automatic calculation script. PHP preferably or javascript.

I want to set up a form that as the user select's the relevant information it changes the price automatically without needing to click a submit button. Very similar to the apple store: http://store.apple.com/us/configure/MC026LL/A?mco=NDE4NDI1Ng

Can someone please provide me with the code or point me to a suitable website where I can get the script.

Many Thanks
0
petewinter
Asked:
petewinter
  • 4
  • 3
  • 2
2 Solutions
 
HonorGodCommented:
One way to do it is to have your input fields be grouped together using the same name attribute.   For example:

<input type='radio' name='CPU' onclick='priceCheck(this)'>


Then, in the function that gets called when the item is selected, it ca:
- determine the group name from the specified object
- determine the selected price, and
- Process all groups, e.g., by name, to compute the total price

Something like this perhaps?
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>
<html>
<head>
<title> Price </title>
<script type='text/javascript'>
  var names = 'CPU,mem'.split( ',' )
  function priceCheck( obj ) {
    var total = 0
    for ( var i = 0; i < names.length; i++ ) {
      var ele = document.getElementsByName( names[ i ] )
      for ( var j = 0; j < ele.length; j++ ) {
        var here = ele[ j ]
        if ( here.checked ) {
          alert( here.value )
          total += parseInt( here.value )
          break
        }
      }
    }
    document.getElementById( 'total' ).value = '$' + total.toFixed( 2 )
  }
</script>
</head>
<body>
<form>
  <input type='radio' name='CPU' onclick='priceCheck(this)' value='100'>8088   $100<br>
  <input type='radio' name='CPU' onclick='priceCheck(this)' value='200'>80186  $200<br>
  <hr>
  <input type='radio' name='mem' onclick='priceCheck(this)' value='300'>16KB   $300<br>
  <input type='radio' name='mem' onclick='priceCheck(this)' value='500'>64KB   $500<br>
  <hr>
 
  Total: <input type='text' id='total' size='5' readonly>
</form>
</body>
</html>

Open in new window

0
 
petewinterAuthor Commented:
Thanks. How do I remove the pop up alert message? http://www.petewinter.com/test_auto.php
0
 
Chris HarteThaumaturgeCommented:
remove the alert (on line 14)
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
HonorGodCommented:
I'm sorry, was there a reason you chose not to give me any credit?
0
 
petewinterAuthor Commented:
Sorry HonorGod. I thought you you posted the second question too. I didn't notice it was by someone else. How do I change it?
0
 
HonorGodCommented:
Open a question in the "General Community Support" section requesting that the question be re-opened so that the point allocation can be corrected.

Include the (short) URL to this question:

http://www.experts-exchange.com/Q_24384938.html

Thanks
0
 
Chris HarteThaumaturgeCommented:
That will teach me to jump in! Contact the moderator I think he can reassign the points.
0
 
petewinterAuthor Commented:
Sorry for the mistake and thanks for your help!
0
 
HonorGodCommented:
Thanks for the grade & points, and the effort required to fix the point allocation.

Good luck & have a great day
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now