Results 1 to 2 of 2

Thread: What's wrong with my onChange function?

  1. #1
    Join Date
    Mar 2011

    What's wrong with my onChange function?

    This is a calculator that calculates how much a user can earn from their referrals depending on the user's Level & Member type. It's supposed to be updating live (onChange) when the user types in new values in the fields, but nothing is happening. Any idea where I went wrong?

    View the page HERE


    <script type="text/javascript">
    function calculate()
    // eval makes the script know the value is a number, and not text
    var myLevel = eval(document.earningsform.level.value);
    var memberType = eval(document.earningsform.type.value);
    var viewed = eval(document.earningsform.viewed.value);
    var Clix = eval(document.earningsform.clix.value);
    var firstValue = eval(document.earningsform.first.value);
    var secondValue = eval(document.earningsform.second.value);
    var thirdValue = eval(document.earningsform.third.value);
    var fourthValue = eval(document.earningsform.fourth.value);
    var fifthValue = eval(document.earningsform.fifth.value);
    var sixthValue = eval(document.earningsform.sixth.value);
    var totalViewed = (viewed + Clix);
    // If Upgraded
    	var firstLevel = eval(.15);
    	var secondLevel = eval(.10);
    	var thirdLevel = eval(.5);
    	var fourthLevel = eval(.3);
    	var fifthLevel = eval(.2);
    	var sixthLevel = eval(.1);
    	var startRate = eval(.50);
    	var rateIncrease = eval(.01);
    	var rate = startRate + (myLevel * rateIncrease);
    	var firstEarnings = rate * firstLevel * (firstValue * totalViewed);
    	// var firstEarnings = rate * firstLevel * (firstValue * totalViewed);
    	// var firstEarnings = rate * firstLevel * (firstValue * totalViewed);
    	// var firstEarnings = rate * firstLevel * (firstValue * totalViewed);
    	// var firstEarnings = rate * firstLevel * (firstValue * totalViewed);
    	// var firstEarnings = rate * firstLevel * (firstValue * totalViewed);
    // If Free
    	var firstLevel = eval(.10);
    	var secondLevel = eval(.5);
    	var thirdLevel = eval(.3);
    	var fourthLevel = eval(.2);
    	var fifthLevel = eval(.1);
    	var startRate = eval(.50);
    	var rateIncrease = eval(.005);
    	var rate = startRate + (myLevel * rateIncrease);
    // This will type in the value of myLevel into the fifth field
    // document.earningsform.fifth.value = myLevel
    <table align="center" cellspacing="0" cellpadding="5">
    	<form action="referralcalculator.php" method="POST" name="earningsform">
    		<td align="center">My Level: </td><td><input type="text" name="level" value="50" size="10" onChange="calculate()"></td><td></td>
    		<td align="center">Member Type: </td><td>
    		<select name="type" onChange="calculate()">
    		<option value="01" selected="selected">Upgraded</option>
    		<option value="02">Free</option>
    		<td align="center">Viewed by each Referral: </td><td><input type="text" name="viewed" value="100" size="10" onChange="calculate()"></td><td>(Daily)</td>
    		<td align="center">Clix by each Referral: </td><td><input type="text" name="clix" value="100" size="10" onChange="calculate()"></td><td>(Daily)</td>
    		<td align="center"><u><b>Referrals:</b></u> </td><td></td><td><u><b>Earned</b></u></td>
    		<td align="center">1st Level: </td><td><input type="text" name="first" size="10" value="5" onChange="calculate()"></td><td><p id="firstcalculate">37.5</p></td>
    		<td align="center">2nd Level: </td><td><input type="text" name="second" size="10" value="5" onChange="calculate()"></td><td>18.75</td>
    		<td align="center">3rd Level: </td><td><input type="text" name="third" size="10" value="5" onChange="calculate()"></td><td>11.25</td>
    		<td align="center">4th Level: </td><td><input type="text" name="fourth" size="10" value="5" onChange="calculate()"></td><td>7.5</td>
    		<td align="center">5th Level: </td><td><input type="text" name="fifth" size="10" value="5" onChange="calculate()"></td><td>3.75</td>
    		<td align="center" colspan="3"><input type="submit" name="submit" value="Calculate"><input type="reset" name="reset" value="Reset"></td>

  2. #2
    Join Date
    Feb 2011
    The hosted version seems to respond OK, but there's no need to use eval anywhere.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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