DoyleChris98 Posted January 11, 2015 Share Posted January 11, 2015 (edited) What i am trying to do is create a text box to enter in a Frequency (122.25mhz). Then on a button press have it call a function to store as a variable, drop the 2 decimal places and convert the number. And return another variable after it is all done. I can figure out how to move the decimal, and convert it. My testing is that I want to display the number to see if the conversions are working right but i cant get it to display. Here is the code. Here is the jsfiddle for it. http://jsfiddle.net/2xz6un9b/ Example 122.25 FREQE = 122.25 FREQE1 = 12225 FREQE2 = 2225 FREQE3 = 4261 FREQO = FREQE3 html <input type="text" id="FREQB"> <button onclick="FREQ()">Frequency</button><p id="FREQO"></p> Javascript function freq(){ //get value from entery var FREQE = document.getElementById("FREQB").value; //dropping 2 decimal places var FREQE1 = FREQE*100; //removing the 1 from the front var FREQE2 = FREQE1 - 10000; //converting to oct var FREQE3 = FREQE2.toString(8); document.getElementById("FREQO").innerHTML = FREQE3;} Edited January 11, 2015 by DoyleChris98 Link to comment Share on other sites More sharing options...
Ingolme Posted January 11, 2015 Share Posted January 11, 2015 Javascript is case sensitive. You've named your function freq() but you're trying to call FREQ() To drop two decimal places you need to multiply by 100. Link to comment Share on other sites More sharing options...
Ingolme Posted January 11, 2015 Share Posted January 11, 2015 In most browsers you can press F12 to open developer tools. Error messages are shown there which you can use to figure out why something is not working. Link to comment Share on other sites More sharing options...
DoyleChris98 Posted January 11, 2015 Author Share Posted January 11, 2015 (edited) Ok i got it to work and display the Octal number now next can i shorten the math part. I got it down to this. Is there a way to shorten it up to just one line of code. I guess this part should be in Javascript portion. { var FREQE = document.getElementById("FREQB").value; var FREQE1 = (FREQE*100)-10000)) var FREQE2 = FREQE1.toString(8); document.getElementById("FREQO").innerHTML = FREQE2;} Edited January 11, 2015 by DoyleChris98 Link to comment Share on other sites More sharing options...
Ingolme Posted January 11, 2015 Share Posted January 11, 2015 Sure it can be done, but it would be a bad idea. It's difficult to read and maintain that kind of code. document.getElementById("FREQO").innerHTML = (document.getElementById("FREQB").value*100-10000).toString(8); Link to comment Share on other sites More sharing options...
DoyleChris98 Posted January 11, 2015 Author Share Posted January 11, 2015 what would be the best way of doing it. This is for Microsoft Flight Simulator, to enter in Communication Frequancies. There in BCD and BCO format in game. Link to comment Share on other sites More sharing options...
Ingolme Posted January 11, 2015 Share Posted January 11, 2015 I don't understand. Does Microsoft Flight Simulator use HTML and Javascript? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now