Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    displaying information

    I am trying to make a program that lets the user put in input and then there is some calculations. I cannot get it to work. I really don't even know if I am on the right track or not. I could use some input on what I am doing wrong please.

    My JS Page:


    Code:
    function Television(Manufacturer,Size,retailPrice,salePrice)
    {
    	this.Manufacturer = Manufacturer;
    	this.Size = Size;
    	this.retailPrice = retailPrice;
    	this.salePrice = salePrice;
    	this.discount = discount;
    }
    Television.prototype.getManufacturer = function()
    {
    	return this.getManufacturer;
    };
    Television.prototype.getSize = function()
    {
    	return this.getSize;
    };
    Television.prototype.getRetailPrice = function()
    { 
    	return this.getRetailPrice;
    }
    Television.prototype.getDiscount = function()
    {
    	return this.getDiscount;
    };
    Television.prototype.getSaleprice = function()
    {
    	return this.getSalePrice;
    };
    Television.prototype.Save = function()
    {
    	var salePrice = this.getRetailPrice() - this.discount;
    };

    My HTML Page:


    Code:
    <!doctype html>
    <html>
    	<head>
    	
    		<title>Television</title>
    		<meta charset = "utf-8" />
    		<script type = "text/javascript" scr="Television.js"></script>
    		<script type = "text/javascript">
    		function doWork()
    			{
    				var Manufacturer = parseFloat(document.myTelevision.Manufacturer.value);
    				var Size = parseFloat(document.myTelevision.Size.value);
    				var retailPrice = parseFloat(document.myTelevision.retailPrice.value);
    				var salePrice = parseFloat(document.myTelevision.salePrice.value);
    				var myTelevision = new Television(Manufacturer, Size, retailPrice, salePrice);
    				myTelevision.getDiscount();
    				document.Television.salePrice.value = myTelevision.getSalePrice();
    		}		
    		</script>
    	</head>
    	<body>
    		
    		<form name= "myTelevision" action="#">
    		<label for = "Manufacturer">Manufacturer:</label>
    		<input type="text" id="Manufacturer" name="Manufacturer"  size="15" />
    		<br />
    		<label for = "getSize">Size:</label>
    		<input type="text" id="getSize" name="Size"/>
    		<br />
    		<label for = "getretailPrice">Retail Price:</label>
    		<input type="text" id="getretailPrice" name="Retail Price" />
    		<br />
    		<label for = "getDiscount">Discount:</label>
    		<input type="text" id="getDiscount" name="Discount" />
    		<br />
    		<input type="button" id="Save" value="Save" onclick="doWork()" />
    			<hr />
    		<label for="getSalePrice">Sale Price:</label>
    		<input type="text" id="getSalePrice" name="SalePrice" />
    		<br />	
    		
    		"Thank You"
    		</form>
    		
    	</body>
    </html>

  • #2
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I forgot to say Thank You

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,096
    Thanks
    23
    Thanked 594 Times in 593 Posts
    It seams to me that the user does pick the Manufacturer and the size, but the price comes from you. Same for the discount.
    Anyway in your form what we're interested in is the math between the price and the discount and placing the results in the Sales Price box and that's all I did.
    Code:
    <!doctype html>
    <html>
    <head>
    <title>Television</title>
    <meta charset = "utf-8" />
    <script type = "text/javascript" scr="Television.js"></script>
    <script type = "text/javascript">
    function doWork(){
    	var price = document.getElementById("getretailPrice").value;
    	var discount = document.getElementById("getDiscount").value/100;
    	document.getElementById("getSalePrice").value = (price * (1 - discount));
    }
    </script>
    </head>
    <body>
    
    <form name= "myTelevision" action="#">
    	<label for = "Manufacturer">Manufacturer:</label>
    	<input type="text" id="Manufacturer" name="Manufacturer"  size="15" /><br />
    
    	<label for = "getSize">Size:</label>
    	<input type="text" id="getSize" name="Size"/><br />
    
    	<label for = "getretailPrice">Retail Price:</label>
    	<input type="text" id="getretailPrice" name="Retail Price" /><br />
    
    	<label for = "getDiscount">PerCent Discount:</label>
    	<input type="text" id="getDiscount" name="Discount" /><br />
    
    	<input type="button" id="Save" value="Save" onclick="doWork()" />
    	<hr />
    	<label for="getSalePrice">Sale Price:</label>
    	<input type="text" id="getSalePrice" name="SalePrice" /><br />
    "Thank You"
    </form>
    
    </body>
    </html>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    I would suggest in order to trap NaN entries

    var price = Number(document.getElementById("getretailPrice").value) || 0;

    name="Retail Price" // a space is not allowed in a name

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •