Jump to content

Button onClick Parameter to Function.


Recommended Posts

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)">



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) {});}
Edited by DoyleChris98
Link to comment
Share on other sites

Am kinda new, so consider this an early careful response, not an expert and not exactly sure what you want to do.

function COMSET(parameter){//code}

for button1 and button2 to do different things...

..a variable to be used in the function COMSET needs to be assigned to it -in this example 'parameter'- in order to be able to recieve parameter1, parameter2 from the respective onClick events in the HTML code. It will revieve then the value of parameter1, respective parameter2, depending on what was clicked.


Then you have to actually incorporate 'parameter' into your code.


for instance:

HTML<input name="COM1" type="button" id="COM1" value="COM1 A" onClick="COMSET(12)"><input name="COM1S" type="button" id="COM1S" value="COM1 S" onClick="COMSET(15)"> JS:function COMSET(parameter){parameter = parameter - 2;alert(parameter);}

would create an alert window with10 if clicked on COM1 and 13 if clicked on COM1s..

Edited by Wardancer
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...