Jump to content

DoyleChris98

Members
  • Posts

    37
  • Joined

  • Last visited

Everything posted by DoyleChris98

  1. Ill try button_1:active { background-color: #00F349; color: #000;} Will that still work with onClick event.
  2. Well I got it to work. But when i go to take it and use the code another way it breaks. What im doing is creating a button with CSS so when it clicks the background turns green and the letter turns black. And im using a mousedown, mouseup to change the style, then onclick to call the function. <div class="button_1" id="button_1" onMouseDown="this.style.background='#00F349'; this.style.color='#000000'" onMouseUp="this.style.background='#000000'; this.style.color='#00F349'" value="1" onclick="NUMBERS(this.value)">1</div>
  3. Well i made the changes that was advised but now when i press a number i get NaN in the text box. I know its a error sending the number to the textfield. Updated code <html><head> <script src="jquery-1.7.1.js"></script> <script src="sprintf.js"></script> <script type="text/javascript"></script> </head> <script> function NUMBERS(num){ var txt = document.getElementById("textfield").value; txt = parseInt(txt) + parseInt(num); document.getElementById("textfield").value = txt; } </script></head> <body><p> <input type="text" id="textfield"></p><p> <input type="button" name="no" value="1" onClick="NUMBERS(this.value)"> <input type="button" name="no" value="2" onClick="NUMBERS(this.value)"> <input type="button" name="no" value="3" onClick="NUMBERS(this.value)"> <input type="button" name="no" value="4" onClick="NUMBERS(this.value)"> <input type="button" name="no" value="5" onClick="NUMBERS(this.value)"> <input type="button" name="no" value="6" onClick="NUMBERS(this.value)"> <input type="button" name="no" value="7" onClick="NUMBERS(this.value)"> <input type="button" name="no" value="8" onClick="NUMBERS(this.value)"> <input type="button" name="no" value="9" onClick="NUMBERS(this.value)"> <input type="button" name="no" value="0" onClick="NUMBERS(this.value)"></p></body></html></body></html>
  4. I have some code that im trying to enter text into a text box with a button click. example you click button 1 and enter 1 into text box. I tried it on jsfiddle it works but just in a regular page it dosent work it gives me [object HTMLInputElement] in the text box. <html><head> <script src="jquery-1.7.1.js"></script> <script src="sprintf.js"></script> <script type="text/javascript"></script> <script>function NUMBERS(num){ var txt = document.getElementById("textfield").value; txt = txt + num; document.getElementById("textfield").value = txt; } </script></head><body><p> <input type="text" id="textfield"></p><p> <input type="button" name="no" value="1" onClick="NUMBERS(this,value)"> <input type="button" name="no" value="2" onClick="NUMBERS(this,value)"> <input type="button" name="no" value="3" onClick="NUMBERS(this,value)"> <input type="button" name="no" value="4" onClick="NUMBERS(this,value)"> <input type="button" name="no" value="5" onClick="NUMBERS(this,value)"> <input type="button" name="no" value="6" onClick="NUMBERS(this,value)"> <input type="button" name="no" value="7" onClick="NUMBERS(this,value)"> <input type="button" name="no" value="8" onClick="NUMBERS(this,value)"> <input type="button" name="no" value="9" onClick="NUMBERS(this,value)"> <input type="button" name="no" value="0" onClick="NUMBERS(this,value)"></p></body></html>
  5. I have a Number from a prompt stored as FREQ, now i want to convert it to HEX, For entry into another variable. 1200 (B10) = 4B0 (B16) but if i put 1200 in as HEX (B16) that turns out 4608 in a converter on my phone. I need to get to 4608. not sure how to take 1200 and turn it into 4608.
  6. I am trying to run a function that will convert a number and output it to a program. I have 2 different buttons and i want them to do a different event but i dont know what parameter to send to the function. Html code <input name="COM1" type="button" id="COM1" value="COM1 A" onClick="COMSET(paramter1)"><input name="COM1S" type="button" id="COM1S" value="COM1 S" onClick="COMSET(parameter2)"> Javascript function COMSET(){var FREQ = Number(prompt ("Frequency"));var jqXHR;$.ajaxSetup({ async: false });jqXHR = $.getJSON("http://" + location.hostname + "/clear_events", function(dane) {});jqXHR = $.getJSON("http://" + location.hostname + "/add_event?name=COM1A&eventname=COM_RADIO_SET", function(dane){});jqXHR = $.getJSON("http://" + location.hostname + "/add_event?name=COM1S&eventname=COM_STBY_RADIO_SET", function(dane){});$.ajaxSetup({ async: true });FREQ = FREQ.toFixed(2);alert(FREQ);var n1 = FREQ.substr(0, FREQ.indexOf("."));n1 = n1.substr(n1.length-2);alert(n1);var n2 = FREQ.substr(FREQ.indexOf(".")+1,2);alert(n1 + " : " + n2);var bcd = (parseInt(n1.charCodeAt(0) - 0x30 )<<12) + (parseInt(n1.charCodeAt(1) - 0x30 )<<8) + (parseInt(n2.charCodeAt(0) - 0x30 )<<4) + parseInt(n2.charCodeAt(1) - 0x30 );alert(bcd);var jqXHR;jqXHR = $.getJSON("http://" + location.hostname + "/set_event_value?name=COM1&value=" + bcd, function(dane) {});jqXHR = $.getJSON("http://" + location.hostname + "/set_event_value?name=com1s&value=" + bcd, function(dane) {});}
  7. I have some code that uses a button to open up a prompt then you enter a number XXX.XX as a frequency. Then convert it to BCD32 then display it. Example 122.30 in decimal to 8752 in BCD32 Here is the code. <html><head></head><script type="text/javascript"></script> <script>function COMSET(){var FREQ = Number(prompt ("Frequency"));//sets to 2 decimal placesFREQ = FREQ.toFixed(2);alert(FREQ);//gets the first 2 characters before the . and drops the 1var n1 = FREQ.substr(0, FREQ.indexOf("."));n1 = n1.substr(n1.length-2);alert(n1);//gets the last 2 characters after the .var n2 = FREQ.substr(FREQ.indexOf(".")+1,2);alert(n1 + " : " + n2);//Converts from Decimal to BCD formatvar bcd = (parseInt(n1.charCodeAt(0) - 0x30 )<<12) + (parseInt(n1.charCodeAt(1) - 0x30 )<<8) + (parseInt(n2.charCodeAt(0) - 0x30 )<<4) + parseInt(n2.charCodeAt(1) - 0x30 );document.getElementById(COM1_ASET).innerHTML=bcd;}</script><body> <input name="COM1" type="button" id="COM1" value="COM1_SET" onClick="TEST()"><p id="COM1_ASET"><p> </body></html>
  8. I am using Microsoft Flight Simulator and 2 programs on it called Simconnect and Websimconnect. FSX <-> Simconnect <-> Websimconnect <-> Webpage Its designed to control things in FSX from a Webpage. One thing it can do is display Radio frequencies and interact with them. The problem is when simconnect reads the radio there not in MHz or KHz, there in BCD16, BCD32, and BCO16. Mainly i want to figure out the BCO16 (binary coded octal 16), how to take BCO16 and convert it to a 4 digit Integer for the Transponder. Transponder is a 4 digit code that each digit runs between 0-7 so 0000-7777. but unlike Binary Base2 or Decimal Base10. BCO16 acts like base 16 instead of base8. So once you got to 0010 it is 16 in BCO16 0100 is 256 and 1000 is 4096. I know i need to use parseInt and to convert the number but not sure what the code hast to be. I know i need to take each digit and parse it out. This is the code to Convert the COM frequency from XXX.XX to BCD format. After the 1 is dropped from the Com freq. var bcd = (parseInt(n1.charCodeAt(0) - 0x30 )<<12) + (parseInt(n1.charCodeAt(1) - 0x30 )<<8) + (parseInt(n2.charCodeAt(0) - 0x30 )<<4) + parseInt(n2.charCodeAt(1) - 0x30 ) but im not sure how to do the BCO16 conversion and i was wondering if somebody could explain it to me. I dont expect it to be done for me but show me how to do it so i can learn it.
  9. I am making a website to get Radio frequencies from Microsoft Flight Simulator through Simconnect on my computer. I would like to get the FREQ from FSX and convert them to 0, 1, 2, 3 decimal places. Ill give a example below and explain it. I want to set COM1 Freq to 3 decimal places 130.250 but where do i put the toFixed(3) at in the code. Gets COM1 Active frequency from FSX <SCRIPT src="../jquery-1.7.1.js"></script><script src="sprintf.js"></script> <script type="text/javascript"></script> function body_onload() {var jqXHR;jqXHR = $.getJSON("http://" + location.hostname + "/add_definition?definition_name=RADIO&name=COM1_A&PropertyName=COM ACTIVE FREQUENCY:1&UnitName=MHz&DatumType=FLOAT32", function(data) {});} Sets variable for it function get_values() {var C1A = document.getElementById("COM1_AD");C1A.innerHTML = definition_data.COM1_A;} Displays the data <BODY onload="body_onload()"><P>COM 1 Active is: <SPAN id="COM1_AD"></SPAN></P></BODY>
  10. 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.
  11. 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;}
  12. 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;}
×
×
  • Create New...