Click to See Complete Forum and Search --> : basic calculations problem


tinernet
10-07-2003, 12:03 PM
this has gone from fairly simple to mind boggelingly complicated. i keep getting an error on line 23, char 43, and it thinks there should be a ";" somwhere...........
HELP!

<script type="text/javascript">
function menchng() {
var cash=document.men.cash.value;
var cashend=(cash-((infbuy*1000)-(flambuy*2000)-(combuy*5000)))+((eval(infsell)*800)+(eval(flamsell)*1500)+(eval(comsell)*4000));
if (cashend<0) {
document.writeln('Not enough money.<br><a href="men.htm">Back</a>');
}
if((infbuy != "")&&(infsell != "")) {
var infbuy=document.men.infbuy.value;
var infsell=document.men.infsell.value;
var infcur=document.men.infcur.value;
var inftot=(infcur+eval(infbuy))-infsell
document.writeln('<b><u>Infantry</u></b><br>');
document.writeln('Infantry Bought: '+infbuy+'<br>');
document.writeln('Infantry Sold: '+infsell+'<br>');
document.writeln('Infantry Total: '+inftot+'<br><br><br>');

elseif((flambuy != "")&&(flamsell != "")) {
var flambuy=document.men.flambuy.value;
var flamsell=document.men.flamsell.value;
var flamcur=document.men.flamcur.value;
var flamtot=(flamcur+eval(flambuy))-flamsell
document.writeln('<b><u>FlameTroopers</u></b><br>');
document.writeln('FlameTroopers Bought: '+infbuy+'<br>');
document.writeln('FlameTroopers Sold: '+infsell+'<br>');
document.writeln('FlameTroopers Total: '+inftot+'<br><br><br>');

elseif((combuy != "")&&(comsell != "")) {
var combuy=document.men.combuy.value;
var comsell=document.men.comsell.value;
var comcur=document.men.comcur.value;
var comtot=(comcur+eval(combuy))-comsell
document.writeln('<b><u>Commandos</u></b><br>');
document.writeln('Commandos Bought: '+infbuy+'<br>');
document.writeln('Commandos Sold: '+infsell+'<br>');
document.writeln('Commandos Total: '+inftot+'<br>');
}
}
document.writeln('Cash Remaning: $'+cashend);
}
</script>

AdamBrill
10-07-2003, 12:11 PM
All of the elseif's should be else if... If that doesn't fix the problem, could you post a link to where you have the page?

tinernet
10-07-2003, 03:15 PM
um nowhere at the mo as tripod seems to be broked. heres the whoe code:

<html>
<head>
<title>:::&lt; Epic Infantry Section &gt;:::</title>
<script type="text/javascript">
function menchng() {
var cash=document.men.cash.value;
var cashend=(cash-((infbuy*1000)-(flambuy*2000)-(combuy*5000)))+((eval(infsell)*800)+(eval(flamsell)*1500)+(eval(comsell)*4000));
if (cashend<0) {
document.writeln('Not enough money.<br><a href="men.htm">Back</a>');
}
if((infbuy != "")&&(infsell != "")) {
var infbuy=document.men.infbuy.value;
var infsell=document.men.infsell.value;
var infcur=document.men.infcur.value;
var inftot=(infcur+eval(infbuy))-infsell
document.writeln('<b><u>Infantry</u></b><br>');
document.writeln('Infantry Bought: '+infbuy+'<br>');
document.writeln('Infantry Sold: '+infsell+'<br>');
document.writeln('Infantry Total: '+inftot+'<br><br><br>');

else if((flambuy != "")&&(flamsell != "")) {
var flambuy=document.men.flambuy.value;
var flamsell=document.men.flamsell.value;
var flamcur=document.men.flamcur.value;
var flamtot=(flamcur+eval(flambuy))-flamsell
document.writeln('<b><u>FlameTroopers</u></b><br>');
document.writeln('FlameTroopers Bought: '+infbuy+'<br>');
document.writeln('FlameTroopers Sold: '+infsell+'<br>');
document.writeln('FlameTroopers Total: '+inftot+'<br><br><br>');

else if((combuy != "")&&(comsell != "")) {
var combuy=document.men.combuy.value;
var comsell=document.men.comsell.value;
var comcur=document.men.comcur.value;
var comtot=(comcur+eval(combuy))-comsell
document.writeln('<b><u>Commandos</u></b><br>');
document.writeln('Commandos Bought: '+infbuy+'<br>');
document.writeln('Commandos Sold: '+infsell+'<br>');
document.writeln('Commandos Total: '+inftot+'<br>');
}
}
document.writeln('Cash Remaning: $'+cashend);
}
</script>
</head>
<body>
<form onsubmit="menchng()" name="men">
<b><u>Infantry</u></b><br>
Infantry buy: <input type="text" name="infbuy" size="20"><br>
Infantry sell: <input type="text" name="infsell" size="20"><br>
Current infantry: <input type="text" name="infcur" size="20"><br><br>
<b><u>FlameTroopers</u></b><br>
FlameTroopers buy: <input type="text" name="flambuy" size="20"><br>
FlameTroopers sell: <input type="text" name="flamsell" size="20"><br>
Current FlameTroopers: <input type="text" name="flamcur" size="20"><br><br>
<b><u>Commandos</u></b><br>
Commandos buy: <input type="text" name="combuy" size="20"><br>
Commandos sell: <input type="text" name="comsell" size="20"><br>
Current Commandos: <input type="text" name="comcur" size="20"><br><br>
Cash: $<input type="text" name="cash" size="20"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

yeah i kno my html is poor il change it all l8r........

AdamBrill
10-07-2003, 07:56 PM
Ok, try this instead:<script type="text/javascript">
function menchng() {
var cash=document.men.cash.value;
var cashend=(cash-((infbuy*1000)-(flambuy*2000)- (combuy*5000)))+((eval(infsell)*800)+(eval(flamsell)*1500)+(eval(comsell)*4000));
if (cashend<0) {
document.writeln('Not enough money.<br><a href="men.htm">Back</a>');
}
if((infbuy != "")&&(infsell != "")) {
var infbuy=document.men.infbuy.value;
var infsell=document.men.infsell.value;
var infcur=document.men.infcur.value;
var inftot=(infcur+eval(infbuy))-infsell
document.writeln('<b><u>Infantry</u></b><br>');
document.writeln('Infantry Bought: '+infbuy+'<br>');
document.writeln('Infantry Sold: '+infsell+'<br>');
document.writeln('Infantry Total: '+inftot+'<br><br><br>');
}else if((flambuy != "")&&(flamsell != "")) {
var flambuy=document.men.flambuy.value;
var flamsell=document.men.flamsell.value;
var flamcur=document.men.flamcur.value;
var flamtot=(flamcur+eval(flambuy))-flamsell
document.writeln('<b><u>FlameTroopers</u></b><br>');
document.writeln('FlameTroopers Bought: '+infbuy+'<br>');
document.writeln('FlameTroopers Sold: '+infsell+'<br>');
document.writeln('FlameTroopers Total: '+inftot+'<br><br><br>');
}else if((combuy != "")&&(comsell != "")) {
var combuy=document.men.combuy.value;
var comsell=document.men.comsell.value;
var comcur=document.men.comcur.value;
var comtot=(comcur+eval(combuy))-comsell
document.writeln('<b><u>Commandos</u></b><br>');
document.writeln('Commandos Bought: '+infbuy+'<br>');
document.writeln('Commandos Sold: '+infsell+'<br>');
document.writeln('Commandos Total: '+inftot+'<br>');
}
document.writeln('Cash Remaning: $'+cashend);
}
</script>You just had a couple of your }'s in the wrong spot. ;)