Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    if / else statement

    Hello again I am having trouble with this program. Could I get someone to please look at this for me. I started out with "" around the salesTax but I changed it to '. I don't know if I need a return statement or not but anyway here it is and thank you very much.

    html page


    Code:
     
    <!doctype html>
    <html>
    	<head>
    		<title>Sales Tax Lookup</title>
    		<meta charset="utf-8" />
    		<script type="text/JavaScript" src="taxOnAmount.js" /></script>
    	</head>
    	<body>
    		<form name="taxes" action="#">
    			
    			<label for="taxAmount">Taxed Amount : </label>
    			<input type="text" name="taxAmount" id="taxAmount" /><br />
    			
    			<label for="salesTax">Sales Tax : </label>
    			<input type="text" name="salesTax" id="salesTax" /><br />
    			
    			<input type="button" id="calculate" value="calculate" onclick="Calculate_Click()" />
    		 </form>
    	</body>
    </html>

    Javascript page


    Code:
    function Calculate_Click()
    {
    	var taxAmount = parseFloat(document.taxes.taxAmount.value);
    	var salesTax =  parseFloat(document.taxes.salesTax.value);
    	
    	//axAmount < 0) || (taxAmount > 99) 
    	//alert ("Tax Amount Must Be between 0 and 99 with no decimal points!");
    	if (taxAmount <= 7){
    		salesTax = '0';
    	}
    	else if (taxAmount <= 21){
    	   salesTax = '1';
    	}
    	else if (taxAmount <=35){
    		salesTax = '2';
    	}
    	else if (taxAmount <= 49){
    		salesTax = '3';
    	}
    	else if (taxAmount <= 64){	
    		salesTax = '4';
    	}
    	else if (taxAmount <= 78){	
    		salesTax = '5';
    	}
    	else if (taxAmount <= 92){	
    		salesTax = '6';
    	}
    	else if (taxAmount <= 99){	
    		salesTax = '7';
    	}
    	else (taxAmount > 99){
    		Alert("You Must Enter A Number Below 99. Thank You");
    	}
    	end if

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Your most immediate problem is that JS does not have or need end if.

    Use the error console.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,030
    Thanks
    0
    Thanked 247 Times in 244 Posts
    There is no "end if" in Javascript. The function is missing the closing }
    You can easily spot these kinds of errors in the Javascript console.

  • #4
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calculate_click not defined

    I fixed the problems mentioned above and I found the console. It tells me that the "calculate_click is not defined"

  • #5
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,215
    Thanks
    12
    Thanked 338 Times in 334 Posts
    either a syntax error or a problem loading the file.

    note that the MIME type (text/javascript) is all lower-case.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,030
    Thanks
    0
    Thanked 247 Times in 244 Posts
    Remove the /

    Code:
    <script type="text/JavaScript" src="taxOnAmount.js" /></script>


  •  

    Tags for this Thread

    Posting Permissions

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