/    Sign up×
Community /Pin to ProfileBookmark

function help – guess this is pretty basic

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>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Portugeezer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...