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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Why doesn't my javascript calculator work?

    It can be found right here: http://arkdesigns.ca/AttilaKomaromiJavaCalculator.htm

    I have javascript enabled on my browsers but it still doesn't work. I see the calculator but pushing the buttons does nothing Any help is appreciated

    My code is:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Javascript Calculator</title>
        <style>
            <!-- CSS STYLES GO HERE -->
                .container {
    			width:500px;
    			height:500px;
    		}
    		.equ {
    			width:99%;
    			height:20px;
    			font-size:20px;	
    			text-align:right;
    			margin-bottom:15px;
    		}
    		table {
    			border:1px solid black;
    			padding:5px;
    			width:100%;
    		}
    		table td {
    			margin:3px;
    			text-align:center;
    			width:20%;	
    		}
    		.buttons {
    			width:100%;
    			height:50px;
    			font-size:15px;	
    		}
    	</style>
        <script type="text/javascript" src="javascript.js">
    	</script>
    </head>
    <body>
    	<div class="container">
        	<table cellspacing="0">
            	<tr>
                	<td colspan="5"><input class="equ" type="input" disabled="disabled" id="equation" value="0"/><input type="hidden" id="previousType" value="-1"/></td>
                </tr>
                <tr>
                	<td><input class="buttons" type="button" name="sin" value="sin" onclick="solve ('sin')" /></td>
                    <td><input class="buttons" type="button" name="cos" value="cos" onclick="solve ('cos')" /></td>
                    <td><input class="buttons" type="button" name="tan" value="tan" onclick="solve('tan')" /></td>
                    <td><input class="buttons" type="button" name="sqrt" value="&radic;" onclick="solve('sqrt')" /></td>
                </tr>
                <tr>
                	<td><input class="buttons" type="button" name="back" value="&larr;" onclick="remove ();"/></td>
                    <td colspan="2"><input class="buttons" type="button" name="erase" value="C" onclick="clear_equation ();" /></td>
                    <td><input class="buttons" type="button" name="divide" value="/" onclick="equation (this.value, 1)"/></td>
                </tr>
                <tr>
                	<td><input class="buttons" type="button" name="seven" value="7" onclick="equation (this.value, 2)"/></td>
                    <td><input class="buttons" type="button" name="eight" value="8" onclick="equation (this.value, 2)"/></td>
                    <td><input class="buttons" type="button" name="nine" value="9" onclick="equation (this.value, 2)"/></td>
                    <td><input class="buttons" type="button" name="multiple" value="*" onclick="equation (this.value, 1)"/></td>
                </tr>
                <tr>
                	<td><input class="buttons" type="button" name="four" value="4" onclick="equation (this.value, 2)"/></td>
                    <td><input class="buttons" type="button" name="five" value="5" onclick="equation (this.value, 2)"/></td>
                    <td><input class="buttons" type="button" name="six" value="6" onclick="equation (this.value, 2)"/></td>
                    <td><input class="buttons" type="button" name="subtract" value="-" onclick="equation (this.value, 1)"/></td>
                </tr>
                <tr>
               	<td><input class="buttons" type="button" name="one" value="1" onclick="equation (this.value, 2)"/></td>
                    <td><input class="buttons" type="button" name="two" value="2" onclick="equation (this.value, 2)"/></td>
                    <td><input class="buttons" type="button" name="three" value="3" onclick="equation (this.value, 2)"/></td>
                    <td><input class="buttons" type="button" name="plus" value="+" onclick="equation (this.value, 1)"/></td>
                </tr>
                <tr>
                	<td colspan="2"><input class="buttons" type="button" name="zero" value="0" onclick="equation (this.value, 2)"/></td>
                    <td><input class="buttons" type="button" name="decimal" value="." onclick="equation (this.value, 3)"/></td>
                    <td><input class="buttons" type="button" name="equal" value="=" onclick="solve ('');"/></td>
                </tr>
            </table>
        </div>
    </body>
    </html>

  • #2
    Banned
    Join Date
    Mar 2012
    Posts
    306
    Thanks
    1
    Thanked 28 Times in 28 Posts
    you haven't posted any javascript

  • #3
    Regular Coder Nile's Avatar
    Join Date
    Jun 2008
    Posts
    280
    Thanks
    2
    Thanked 46 Times in 46 Posts
    It's because the file you're linking to in the script doesn't exist (javascript.js).

  • #4
    Banned
    Join Date
    Mar 2012
    Posts
    306
    Thanks
    1
    Thanked 28 Times in 28 Posts
    Quote Originally Posted by Nile View Post
    It's because the file you're linking to in the script doesn't exist (javascript.js).
    It does in my FF v11. When I view the source of the link and click on the js file name (which also appears as a link in the source) the file opens up. But there are errors in it.

  • #5
    Regular Coder Nile's Avatar
    Join Date
    Jun 2008
    Posts
    280
    Thanks
    2
    Thanked 46 Times in 46 Posts
    Hmmm, that's odd. I get a 404 error.


    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <html dir=ltr>
    
    <head>
    <style>
    a:link			{font:8pt/11pt verdana; color:FF0000}
    a:visited		{font:8pt/11pt verdana; color:#4e4e4e}
    </style>
    
    <META NAME="ROBOTS" CONTENT="NOINDEX">
    
    <title>The page cannot be found</title>
    
    <META HTTP-EQUIV="Content-Type" Content="text-html; charset=Windows-1252">
    </head>
    
    <script> 
    function Homepage(){
    <!--
    // in real bits, urls get returned to our script like this:
    // res://shdocvw.dll/http_404.htm#http://www.DocURL.com/bar.htm 
    
    	//For testing use DocURL = "res://shdocvw.dll/http_404.htm#https://www.microsoft.com/bar.htm"
    	DocURL = document.URL;
    		
    	//this is where the http or https will be, as found by searching for :// but skipping the res://
    	protocolIndex=DocURL.indexOf("://",4);
    	
    	//this finds the ending slash for the domain server 
    	serverIndex=DocURL.indexOf("/",protocolIndex + 3);
    
    		//for the href, we need a valid URL to the domain. We search for the # symbol to find the begining 
    	//of the true URL, and add 1 to skip it - this is the BeginURL value. We use serverIndex as the end marker.
    	//urlresult=DocURL.substring(protocolIndex - 4,serverIndex);
    	BeginURL=DocURL.indexOf("#",1) + 1;
    	
    	urlresult=DocURL.substring(BeginURL,serverIndex);
    				
    	//for display, we need to skip after http://, and go to the next slash
    	displayresult=DocURL.substring(protocolIndex + 3 ,serverIndex);
    
    	InsertElementAnchor(urlresult, displayresult);
    }
    
    function HtmlEncode(text)
    {
        return text.replace(/&/g, '&amp').replace(/'/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
    }
    
    function TagAttrib(name, value)
    {
        return ' '+name+'="'+HtmlEncode(value)+'"';
    }
    
    function PrintTag(tagName, needCloseTag, attrib, inner){
        document.write( '<' + tagName + attrib + '>' + HtmlEncode(inner) );
        if (needCloseTag) document.write( '</' + tagName +'>' );
    }
    
    function URI(href)
    {
        IEVer = window.navigator.appVersion;
        IEVer = IEVer.substr( IEVer.indexOf('MSIE') + 5, 3 );
    
        return (IEVer.charAt(1)=='.' && IEVer >= '5.5') ?
            encodeURI(href) :
            escape(href).replace(/%3A/g, ':').replace(/%3B/g, ';');
    }
    
    function InsertElementAnchor(href, text)
    {
        PrintTag('A', true, TagAttrib('HREF', URI(href)), text);
    }
    
    //-->
    </script>
    
    <body bgcolor="FFFFFF">
    
    <table width="410" cellpadding="3" cellspacing="5">
    
      <tr>    
        <td align="left" valign="middle" width="360">
    	<h1 style="COLOR:000000; FONT: 13pt/15pt verdana"><!--Problem-->The page cannot be found</h1>
        </td>
      </tr>
      
      <tr>
    
        <td width="400" colspan="2">
    	<font style="COLOR:000000; FONT: 8pt/11pt verdana">The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.</font></td>
      </tr>
      
      <tr>
        <td width="400" colspan="2">
    	<font style="COLOR:000000; FONT: 8pt/11pt verdana">
    
    	<hr color="#C0C0C0" noshade>
    	
        <p>Please try the following:</p>
    
    	<ul>
          <li>If you typed the page address in the Address bar, make sure that it is spelled correctly.<br>
          </li>
    	  
          <li>Open the 
    	  
    	  <script>
    	  <!--
    	  if (!((window.navigator.userAgent.indexOf("MSIE") > 0) && (window.navigator.appVersion.charAt(0) == "2")))
    	  { 
    	  	Homepage();
    	  }
    	  //-->
    	   </script>
    
    	   home page, and then look for links to the information you want.</li>
    	   
          <li>Click the <a href="javascript:history.back(1)">Back</a> button to try another link.</li>
    
        </ul>
        
        <h2 style="font:8pt/11pt verdana; color:000000">HTTP 404 - File not found<br>
        Internet Information Services<BR></h2>
    	 
    	<hr color="#C0C0C0" noshade>
    	
    	<p>Technical Information (for support personnel)</p>
    	
    <ul>
    <li>More information:<br>
    
    <a href="http://www.microsoft.com/ContentRedirect.asp?prd=iis&sbp=&pver=5.0&pid=&ID=404&cat=web&os=&over=&hrd=&Opt1=&Opt2=&Opt3=" target="_blank">Microsoft Support</a>
    </li>
    </ul> 
    
        </font></td>
      </tr>
      
    </table>
    </body>
    </html>

  • #6
    Banned
    Join Date
    Mar 2012
    Posts
    306
    Thanks
    1
    Thanked 28 Times in 28 Posts
    Quote Originally Posted by Nile View Post
    Hmmm, that's odd. I get a 404 error.
    Like I said, when I view the source of the posted link in FF v11 and then click the link to the js file that appears in FF's "view page source" window, it opens up the js file. But it's a mixture of html and js functions and so it's no wonder the op's calculator doesn't work. The file the js link points to exists but I think the op has linked to an incorrect file.

  • #7
    Regular Coder Nile's Avatar
    Join Date
    Jun 2008
    Posts
    280
    Thanks
    2
    Thanked 46 Times in 46 Posts
    No... The file the OP links to does not exist. The mixture is the code of the 404 error page.

  • #8
    Banned
    Join Date
    Mar 2012
    Posts
    306
    Thanks
    1
    Thanked 28 Times in 28 Posts
    It could be. I didn't take a close look at the code. As soon as I saw html mixed up in a supposedly js file I thought this is a major stuff up and closed the window without looking at the actual code.


  •  

    Posting Permissions

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