• symbol
• exchange
• price
• quantity
• order_type
• side
and two methods:
• getDescription()
• getCost()
Write an html page that will submit a form with the OrderDescription attributes to a function that will initiate this object and will show alert box with order description and how much net will cost.
Answer:
<script language="JavaScript">
function ShowResults(){
StockOrder=new Object();
StockOrder.symbol=document.myform.symbol.value;
StockOrder.exchange=document.myform.exchange.value;
StockOrder.price=document.myform.price.value;
StockOrder.quantity=document.myform.quantity.value;
StockOrder.order_type=document.myform.order_type.value;
StockOrder.side=document.myform.side.value;
StockOrder.getCost = function() { return StockOrder.price * StockOrder.quantity;}
StockOrder.getDescription = function() { return "Symbol is "+StockOrder.symbol+"\nExchange
is "+StockOrder.exchange+"\nPrice is "+StockOrder.price+"\nQuantity
is "+StockOrder.quantity+"\nOrder Type is "+StockOrder.order_type+"\nSide
is "+StockOrder.side;}
alert("Description:\n"+StockOrder.getDescription()+"\n\nNet Cost
is "+StockOrder.getCost());
}
</script>
<html><head><title>My Page</title><head></head>
<body>
<form name="myform" action="" method="post">
symbol<input name="symbol" type="text"><br>
exchange<input name="exchange" type="text"><br>
price<input name="price" type="text"><br>
quantity<input name="quantity" type="text"><br>
order type<input name="order_type" type="text"><br>
side<input name="side" type="text"><br>
<input name="mybutton" type="button" value="Submit"
onClick="return ShowResults()">
</form>
</body>
</html>
===========================================================
Example: