• General
    • Home
    • Contact Us
    • Privacy Policy
    • Sitemap
  • Photographs
    • 2017
    • 2016
    • 2015
  • Literature
    • Poems
  • News
    • Announcements
    • Charity
    • Legal
    • Medicine
    • Politics
  • Education
    • Code Samples
      • Basic
      • Simple
      • Intermediate
      • Advanced
      • Tips
    • History
    • Literature
    • Quotes
    • Videos
    • Vocabulary
  • Entertainment
    • Art
    • Humor
    • Photos
    • Video
  • Technology
    • Software
      • Support
      • Tweaks
    • Company
    • Science
    • Security
Major Mike

Knowledge is Power - Share the Power

Tip Calculator [SIMPLE]

September 8, 2015 by GµårÐïåñ

A simple number manipulation and validation example.

	<form action="javascript:void(calculate())">
		<table>
			<tr><td colspan="2"><h1>Tip Calculator</h1></td></tr>
			<tr><td style="text-align:right">Amount $ </td><td style="text-align:left"> <input type="text" id="amount" size="20" placeholder="24.35" pattern="^\d*(\.\d{2}$)?" title="CURRENCY NUMBER, 2 DECIMAL PLACES (ie: 12.34)" required /></td></tr>
			<tr><td style="text-align:right">Tip % </td><td style="text-align:left"> <input type="text" id="tip" size="20" placeholder="15" pattern="\d*" title="WHOLE NUMBER, NO DECIMALS (ie: 15)" required /></td></tr>
			<tr><td style="text-align:center" colspan="2"><hr/></td></tr>
			<tr><td style="text-align:right">Total $ </td><td style="text-align:left"> <strong id="total">---</strong></td></tr>
			<tr><td style="text-align:center" colspan="2"><hr/></td></tr>
			<tr><td style="text-align:center" colspan="2"><input type="submit" value="Calculate Tip Amount" class="button" /></td></tr>
			<tr><td style="text-align:center" colspan="2"><span id="error"></span></td></tr>
		</table>
	</form>
	<script type="text/javascript">
		var amount = document.getElementById("amount");
		var tip = document.getElementById("tip");
		var total = document.getElementById("total");
		
		function calculate() {
			var a = parseFloat(amount.value);
			var t = parseInt(tip.value) / 100;
							
			total.innerHTML = ((a*t)+a).toFixed(2);
			console.log("Amount : $" + a + "\nTip : " + (t*100) + "%\nTip Amount : $" + (a*t) + "\nTotal Bill : $" + ((a*t)+a));
		};
	</script>
DEMO | DOWNLOAD
Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail
Posted in: Education, Simple Tagged: code, JavaScript, simple level
← Ivory Ban Moves One Step Closer to Law
9/11 Remembrance →

Show Your Support – We Don’t Believe in Disruptive Ads

Donate in one of two ways :
(BitCoin - preferred)
1BTshbqMSx5AHrDFLEa1YdPAy5EFzRSjr9
(PayPal)
September 2015
M T W T F S S
« Aug   Oct »
 123456
78910111213
14151617181920
21222324252627
282930  

Semper Fidelis

Always Faithful, Always Forward
United States Marine Corp

Places to find me:

StackExchange profile for GµårÐïåñ at StackExchange

Google+ ➠

Twitter : verified ➠Follow

GitHub ➠Follow @GuardianMajor

ello ➠

deviantArt profile for GµårÐïåñ on deviantArt

Facebook i have made a personal choice after their "name policy" witch hunt which repeats every 2 years it seems at the whim of the "bully mob" (even when they make you jump through hoops and verify you), to just quit it and be done with it, they are not worth my time. I don't need it, I don't miss it, in fact it has made my life more productive and void of gross hate, vitriol and drivel. To those who say they can't stay in touch if I am not on there, if you can't reach me because I am not on Facebook, then you are not trying AT ALL - therefore, good riddance.

Scribd profile for GµårÐïåñ on Scribd

NoScript/FLashGot (Informaction) profile for GµårÐïåñ on Informaction Forums

Subjects

1896 1962 1948 history 1789 1946 daily pic 1898 1959 1934 1956 1968 1938 1927 1935 1877 1943 2000 1937 1902 1915 1954 1961 1889 1916 1994 1812 1949 1917 has_video 1993 1967 1945 1918 1985 1901 1965 1998 annual 1992 1969 1981 1942 1953 1966 1939 1862 1865 1986 1944 1919 1859 1977 1922 1955 1980 1972 national park vocabulary 1990 1964 1846 1989 holiday 1950 1971 1970 1952 has_audio 1951 1973 1941 1984 JavaScript event 1908 1863 1976 1776 1870 1960 1974 code 1983 1957 1991 1947 1933 1995 1864 memorial 1911 1982 1886 1861 1975 1963 1940 1914 1979

Archives

Access Options

  • Log in
  • Entries RSS
  • Comments RSS
  • ∞ Guardian International
🎔
Brought to You
by Guardian International

Copyright © 2007-2018 Major Mike | Privacy Policy | DMCA | Contact
fortitudo fortis defendit

McAfee SecureNorton by SymantecVirusTotal