As part of an assignment I need to create some functions but I’m having trouble getting it right
I’m not sure how to get the function buyshares working – I’m confused with the syntax
for example
ONCLICK = “buyShares(0,document.trading.ssBuy.value)” >
I need to write a function to get the new value input (above) added to the shareholding value.
code below
<html>
<head> SHARE TRADING SYSTEM
<title>q3 </title>
<script language=”JavaScript” >
var companies = [‘SS’,’MA’,’RB’,’PC’];
var sharePrices = [25.44,83.33,88.89,24.44];
var shareHoldings = [104,23745,12945,84000];
function refreshHoldings()
{
document.holdings.ssHold.value = shareHoldings[0];
document.holdings.mdHold.value = shareHoldings[1];
document.holdings.rbHold.value = shareHoldings[2];
document.holdings.pcHold.value = shareHoldings[3];
}
;
function buyShares()
{
};
function sellShares()
{
};
function alert1()
{
window.alert(“You cannot purchase more than 100,000 shares”)
};
function alert2()
{
window.alert(“You do not have enough shares to sell”)
};
</script>
</head>
<body>
<FORM NAME = “trading”>
<BR>
You may buy or sell the following shares
<BR><BR>
Silent Spring Petrochemicals plc
<BR>
<INPUT TYPE = “button”
VALUE = “Buy”
ONCLICK = “buyShares(0,document.trading.ssBuy.value)” >
<INPUT TYPE = “text”
NAME = “ssBuy”
VALUE = “” >
<INPUT TYPE = “button”
VALUE = “Sell”
ONCLICK = “sellShares(0,document.trading.ssSell.value)” >
<INPUT TYPE = “text”
NAME = “ssSell”
VALUE = “”>
<BR>
Megadeath Armaments Corp.
<BR>
<INPUT TYPE = “button”
VALUE = “Buy”
ONCLICK = “buyShares(1,document.trading.mdBuy.value)” >
<INPUT TYPE = “text”
NAME = “mdBuy”
VALUE = “” >
<INPUT TYPE = “button”
VALUE = “Sell”
ONCLICK = “sellShares(1,document.trading.mdSell.value)” >
<INPUT TYPE = “text”
NAME = “mdSell”
VALUE = “”>
<BR>
Reckitt and Bodger plc
<BR>
<INPUT TYPE = “button”
VALUE = “Buy”
ONCLICK = “buyShares(2,document.trading.rbBuy.value)” >
<INPUT TYPE = “text”
NAME = “rbBuy”
VALUE = ” >
<INPUT TYPE = “button”
VALUE = “Sell”
ONCLICK = “sellShares(2,document.trading.rbSell.value)” >
<INPUT TYPE = “text”
NAME = “rbSell”
VALUE = “”>
<BR>
Pravda Communications Corp
<BR>
<INPUT TYPE = “button”
VALUE = “Buy”
ONCLICK = “buyShares(3,document.trading.pcBuy.value)” >
<INPUT TYPE = “text”
NAME = “pcBuy”
VALUE = ”>
<INPUT TYPE = “button”
VALUE = “Sell”
ONCLICK = “sellShares(3,document.trading.pcSell.value)” >
<INPUT TYPE = “text”
NAME = “pcSell”
VALUE = “”>
<BR>
</FORM>
<FORM NAME = “holdings”>
<BR>
You hold the following shares
<BR><BR>
Silent Spring Petrochemicals plc.
<BR>
<INPUT NAME = “ssHold”
“TYPE = “text”
VALUE = ” >
<BR>
Megadeath Armaments Corp.
<BR>
<INPUT NAME = “mdHold”
“TYPE = “text”
VALUE = ” >
<BR>
Reckitt and Bodger plc.
<BR>
<INPUT NAME = “rbHold”
“TYPE = “text”
VALUE = ” >
<BR>
Pravda Communications Corp.
<BR>
<INPUT NAME = “pcHold”
“TYPE = “text”
VALUE = ” >
<BR>
Press button to update………….
<INPUT TYPE = “button”
VALUE = “Refresh holdings”
ONCLICK = “refreshHoldings()”>
</FORM>
</body>
</body>
</html>