Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Automatic Calculation Script

Posted on 2009-05-06
10
Medium Priority
?
248 Views
Last Modified: 2012-05-06
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
Comment
Question by:petewinter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
10 Comments
 
LVL 41

Accepted Solution

by:
HonorGod earned 1800 total points
ID: 24315103
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
 

Author Comment

by:petewinter
ID: 24315195
Thanks. How do I remove the pop up alert message? http://www.petewinter.com/test_auto.php
0
 
LVL 17

Assisted Solution

by:Chris Harte
Chris Harte earned 200 total points
ID: 24315327
remove the alert (on line 14)
0
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
LVL 41

Expert Comment

by:HonorGod
ID: 24315623
I'm sorry, was there a reason you chose not to give me any credit?
0
 

Author Comment

by:petewinter
ID: 24315889
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
 
LVL 41

Expert Comment

by:HonorGod
ID: 24315937
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
 
LVL 17

Expert Comment

by:Chris Harte
ID: 24315980
That will teach me to jump in! Contact the moderator I think he can reassign the points.
0
 

Author Closing Comment

by:petewinter
ID: 31578463
Sorry for the mistake and thanks for your help!
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24325950
Thanks for the grade & points, and the effort required to fix the point allocation.

Good luck & have a great day
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question