View Full Version : Probably an easy solution...

09-06-2008, 07:04 AM
I can't figure out why my form isn't working. Granted, it's been a while since I've done any JavaScript...

Anyway, here's what I have:



<title>Expected Value Calculator</title>

<script type="text/javascript">

function solvepy(form)
a = parseInt(form.a.value);
b = parseInt(form.b.value);
c = parseInt(form.c.value);
d = parseInt(form.d.value);
form.e.value = (c+d);
e = parseInt(form.e.value);
form.f.value = (a*e)
f = parseInt(form.f.value);
form.g.value = (b*d);
g = parseInt(form.g.value);
form.h.value = (f-g);
h = parseInt(form.h.value);


<script type="text/javascript">

function clearform()
document.ev.a.value= " ";
document.ev.b.value= " ";
document.ev.c.value= " ";
document.ev.d.value= " ";
document.ev.e.value= " ";
document.ev.f.value= " ";
document.ev.g.value= " ";
document.ev.h.value= " ";



<p>For Win and Lose %, please round to the nearest whole number. For instance, if your chance to win is 19.4% and your chance to lose is 80.6, round them to 19 and 81, respectively.</p>

<form name="form">

<input type=text name=a size=4> - Win %<br>
<input type=text name=b size=4> - Lose %<br>
<input type=text name=c size=4> - Pot Size before Opponent Bets<br>
<input type=text name=d size=4> - Opponent's bet<br>
<input type=text name=e size=4 readOnly=true> - Total Pot Value<br>
<input type=text name=f size=4 readOnly=true> - Expected Profit<br>
<input type=text name=g size=4 readOnly=true> - Expected Loss<br>
<input type=text name=h size=4 readOnly=true> - Expected Value
<input type="button" value ="Calculate" name="Submit" onClick="solvepy(this.form)"><br>
<input type="button" name="Submit2" value="Clear" onClick="clearform()">



Also, if anyone feels like helping me code it to round the Win and Loss % to a whole number (like 19.4 to 19) and to format Expected Profit, Loss, and Value as money (two places after the decimal point), that'd be great as well. I forget how to do that.

09-06-2008, 08:46 AM
Two things jump out at me:

You need to declare your variables, otherwise they will be confused with the elements of the same names.

The readonly attribute shouldn't be set like you have it:

<input type=text name=e size=4 readOnly=true>

rather like so:

<input type=text name=e size=4 readonly>

There could be other problems.

09-06-2008, 06:47 PM
Thanks, jscheuer. I have forgotten so much JS.