473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Calculation with dropdown and input box

I'm really new to all this and have just pieced together from W3schools. What I would like to try and create form that once entering a number into a text box calculates a selection in a dropdown list and displays it in another text box once a submit button is clicked. The code I have thus far is as follows...Additionally I have attached a photo of what I wish the results to look like.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2.  
  3. <html> 
  4.  
  5. <head>
  6.  
  7. <script type="text/javascript">
  8.  
  9. function findTotal()
  10. {
  11.  
  12.     var icing = parseFloat(document.getElementById('icing').value);
  13.  
  14.     var servings = Number(document.getElementById('servings').value);
  15.  
  16.     var total = icing * servings;
  17.  
  18.  
  19. }
  20.  
  21. </script> 
  22.  
  23.  
  24.  
  25. </head>
  26.  
  27. <body>
  28.  
  29. <B>Icing:</B> <select id="icing">
  30. <option>(Make a selection)</option>
  31. <option value num="2.25">Whipped Cream</option>
  32. <option value num="3.50">Butter Cream</option>
  33. <option value num="4.00">Fondant</option>
  34. </select>
  35. <br>
  36.  
  37. <B>Servings:</B> <input id="servings"><br>
  38.  
  39. <button onclick="findTotal();">Calculate Total</button>
  40.  
  41. <input type="text" id="" size="20">
  42.  
  43. </body> 
  44.  
  45. </html>
  46.  

Attached Images
File Type: png Form.png (3.8 KB, 2328 views)
Feb 24 '13 #1
2 5766
zmbd
5,501 Expert Mod 4TB
By, simply stating that your code "doesn't work" or what am I missing here, well you actually don't really say one way or the other, along with code that appears to have had very little if any troubleshooting performed expecting someone to help doesn't usually result in much of an answer and may result in your thread being deleted.

Instead, please tell us what you were expecting to happen, what actually happened, for each error (if any): the EXACT title, error number, and descriptions that occurred and at what line in your posted code the error occurred.

These are the minimum requirements for posting a question of this nature.

Also, please read the FAQ and Posting Guidelines. If your post were to be read within the strictest interpretation of these expectations, your post would be in violation of them.
Feb 24 '13 #2
What was Expected:
1. Person would select option from drowdown list.
Ex: Whipped Cream
2. Person would enter number into textbox.
3. Person will click button to calculate.
4. Output will be displayed in textbox.

I have assigned each option within the dropdown list to a number for example "Whipped Cream" holds the value of 2.25. When a person selects "Whipped Cream", enters 25 in the textbox, and clicks the button, the following calculation will occur (2.25*25) the result will the be displayed in a textbox.


When I run my own code nothing occurs.
Feb 25 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Aspersion | last post by:
I'm building an ASP page that has a lot of text and graphics. There is a calculation facility on the page. The user enters several numbers in a form and presses a button to see the calculated...
1
by: middletree | last post by:
For an ASp Intranet app, I have some code that should work, but I am not able to make it happen for some reason, after spending considerable time on this. I am pretty thick when it comes to...
6
by: chuskarl | last post by:
Hi, I just starting learning javascripe by myself and have quick question if anyone can help. I already checked recent post and couldn't find any similar one. I have a few pairs of checkbox and...
10
by: hacorbin | last post by:
I have a VB.NET program I am creating that sums 7 textboxes and displays their total in a total textbox. code: Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As...
3
by: groups2 | last post by:
When you press the down key while in an input field the default behavior for some event creates a dropdown of the previously input text. What event creates that behavior and how do I stop it ? ...
3
by: mattmao | last post by:
Okay, I was asked by a friend about the result of this limit: http://bbs.newwise.com/attdata/forumid_14/20070922_fe7f77c81050413a20fbDWYOGm7zeRj3.jpg Not n->zero but n-> + infinite I really...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
11
by: tokcy | last post by:
Hi everyone, I am new in php and ajax, i am facing the prob while i click on element of first drop down then in second dropdown all element showl come from database. I mean i have three dropdown 1....
12
by: brossyg | last post by:
I have a very simple price times quantity calculation. The input is STWCORQuant: <input name="STWCORQuant" class="contactitalicbold" id="STWCORQuant" onChange="javascript:STWCORPrice();"...
1
by: Phoumano Somvie | last post by:
I am trying to do some calculation with this form but some input fields are resulting NaN. Can anyone explain the error and a fix? Thanks <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.