Jscript calculation within form

Posted on 2012-03-19
Last Modified: 2012-03-20
Have a form with three types of room cleaning services, each with their own price per room. When the number of rooms is chosen for one or more of the types I want it to calculate the total price.
Question by:gardena
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
LVL 11

Accepted Solution

SANDY_SK earned 250 total points
ID: 37736966
Use This script
var basicRoomCost = 20;
var standardRoomcost = 30;
var executiveRoomCost = 40;

function updatesum(){
	var numBasic = document.getElementsByName('basicroom')[0].value;
	var numStandard = document.getElementsByName('standardroom')[0].value;
	var numExecutive = document.getElementsByName('executiveroom')[0].value;

	var total = (numBasic*basicRoomCost)+(numStandard*standardRoomcost)+(numExecutive*executiveRoomCost);

	document.getElementsByName('totalValue')[0].value = total;

Open in new window


Author Closing Comment

ID: 37740969
Thanks for your prompt reply, that works very well.

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

752 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