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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now