Results 1 to 3 of 3

Thread: Probably an easy solution...

  1. #1
    Join Date
    Jan 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Probably an easy solution...

    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:

    HTML Code:
    <html>
    
    <head>
    
    <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>
    
    <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= " ";
    	}
    </script>
    
    </head>
    
    <body>
    
    <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
    <br>
    <input type="button" value ="Calculate" name="Submit" onClick="solvepy(this.form)"><br>
    <input type="button" name="Submit2" value="Clear" onClick="clearform()">
    </form>
    
    </body>
    
    </html>
    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.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Two things jump out at me:

    1. You need to declare your variables, otherwise they will be confused with the elements of the same names.
    2. The readonly attribute shouldn't be set like you have it:

      HTML Code:
      <input type=text name=e size=4 readOnly=true>
      rather like so:

      HTML Code:
      <input type=text name=e size=4 readonly>


    There could be other problems.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jan 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks, jscheuer. I have forgotten so much JS.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •