Home > Enterprise >  Call one set of JS code instead of another
Call one set of JS code instead of another

Time:11-25

I have a RF to L-band calculator/converter that I am designing and developing for my FT job. Now C-Band was easy as we only use one frequency range. KU band we have 2 frequency ranges. So for that calculator I want to use Radio Buttons. When an engineer Checks Radio 1 they use the functions coded for that Freqeuncy Range, if they Check Radio 2, they use the functions coded for that frequency range.

What can I do to call this when the radio is .checked?

Should I create an array of variables that assign functions to? I'm pretty new to JS. So let me know if I am not clear. TIA.

CodePudding user response:

NVM. I think I figured out a work around.

I will use "If a is check var b = freqOne else b = freqTwo".

CodePudding user response:

You can match function names to radio button values

function foo() {
    console.log("foo was called");
}

function bar() {
    console.log("bar was called");
}

function loremipsum() {
    console.log("loremipsum was called")
}

function test(item) {
    window[item.value]();
}
<label>Foo <input type="radio" name="something" value="foo" onclick="test(this)"></label>
<label>Bar <input type="radio" name="something" value="bar" onclick="test(this)"></label>
<label>Lorem <input type="radio" name="something" value="loremipsum" onclick="test(this)"></label>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related