JavaScript - Base Convertion
Hi I am working on a base converting calculator. Same as this calculator on this link. http://www.asknumbers.com/BaseNumberConversion.aspx. I am only working on bases from 2- 10 inclusive. Here is the coding I did but the problem is i cant get the output once the user inputs the "To base". Can some one help.
<!-- Base Changing.html <!-- ======================================================= --> <head> <title>Base changing </title> <script type="text/javascript"> function BaseConv() // // { var Xnumber=document.getElementById("dnumberArea").value; var XBase=document.getElementById("dbaseArea").value; //var XBase=parseInt(XBase); var BBase=document.getElementById("bbaseArea").value; //BBase=parseInt(BBase); var exp=Math.log(Xnumber)/Math.log(XBase); //Xnumber=Math.pow(XBase,exp); //log var D=1+ Math.floor(exp); var str=""; count=0; while(count<D){ digit = Xnumber%XBase; Xnumber = Math.floor(Xnumber/XBase); str= digit + str; count++; } document.getElementById("bnumberArea").value=str; } </script> </head> <body> <div style="text-align: center"> <h2>base changing</h2> <hr/> <br><br> Input number <input type="text" id="dnumberArea" size="" Onchange="BaseConv();"/> From base <input type="text" id="dbaseArea" size="" Onchange="BaseConv();"/> <br/><br/> Output number <input type="text" id="bnumberArea" size="" Onchange="BaseConv()"/> To base <input type="text" id="bbaseArea" size="" ;"/> </div> </body> </html> Similar TutorialsI'm using <base href> to set my HTML path for links, and chdir() to set PHP's base path. (Entering site at www.mysite.com/account then resetting my paths back to root for simplicity). Both of these are working fine, however I've found Javascript ignores <base href> so it's working directory is still a subfolder of root. OK - so I could add '../' to all Javascript links (which is what I was trying to get away from!) but I've read that it's only IE that ignores <base href> and other browsers accept it. This will mean my links break unless I either stop using <base href> entirely and go back to using '../' in ALL links, or I can find a way to set Javascript's base link pointer... This is driving me crazy! Any ideas of how to do it? Ok Codies .... I am still new to javascript and trying to learn on my own to incress my productivity with my job so this is what I need .... I have to call customers back in a two hour window but that two hour window has to be entered on mountain time ... than I am in central time .. than what ever time zone my client is in. So what I am trying to do is ... I hit a drop down and select the Time zone ... than that pulls the two hour windows in the next drop down will give me the resulting 2 hour window for the Moutain time. I now its a simple convertion but when your dealing with 50 clients a day and trying not to over book each two hour slot ... well i start making mistakes. Any advice on a way I could build this ... I have tryed to nest an if statement to a drop down in html and it blew up on me. Hello, I came across a very odd browser behavior when trying to modify a css class using javascript and at the same time having a base html statement in my html file. Without the base html statement, all browsers work fine and I can change the css class definition using javascript easily. With a base html statement, only FireFox still works while Internet Explorer and Google Chrome dont work anymore. If there is a cross-domain issue, while one browser does work and the others dont? An example of what I'm talking about, with the base statement: http://freebsdcluster.org/~casaschi/...mple-base.html Without the base statement: http://freebsdcluster.org/~casaschi/...le-nobase.html Any idea how to tweak the code in the case with the base html statement in order for the javascript to work with all browser (modifying the class definition) ??? Keep in mind, I dont want a suggestion of another way to change the color, this is only an example. I want to be able to manipulare css classes with javascript when a base html statement is in my html code. This is essentially the code: Code: <!-- --> <base href='http://www.google.com'> <style id='myStyle' type='text/css'> .myStyle { color: red; } </style> <script type="text/javascript"> var lastColor = 'red'; function toggleColor() { lastColor = lastColor == 'red' ? 'green' : 'red'; myObject = document.getElementById('myStyle'); if (myObject.sheet) { myObject.sheet.cssRules[0].style.color = lastColor; } // Mozilla style if (myObject.styleSheet) { myObject.styleSheet.rules[0].style.color = lastColor; } // IE style } </script> <a href="javascript: toggleColor();"><span class=myStyle>click here to toggle color</span></a> Thanks in advance... |