Q: HTML5 - choose formula for output element based on input I am designing a simple calculator, which has 3 inputs and one output.
I wonder if it's possible to change the formula the output element "uses", based on which input-fields are used (*).
For example, we have tree inputs: Input A, Input B and Input C


*

*If A and B are used (and C is empty), then the formula for Output should be "A+B"

*If A and C are used (and B is empty), then the formula for Output should be "A*C"

*If B and C are used (and A is empty), then the formula for Output should be "B/C"


So, how can I change the formula used for the output element, based on the used inputs?
This is a simplified example, I hope you get the point :-)
As requested, here's some example code
[code]
    <!DOCTYPE html>
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta charset="UTF-8"></meta>
    <script>
    function Test(){
    <!--alert('Formula change!');-->

    if (input_a.valueAsNumber && input_b.valueAsNumber){
    alert('Formula One');
    o.value=input_a.valueAsNumber+input_b.valueAsNumber;
    }

    if (input_b.value && input_c.value){
    alert('Formula Two');
    o.value=input_a.valueAsNumber*input_c.valueAsNumber;
    }

    if (input_a.value && input_c.value){
    alert('Formula Three');
    o.value=input_b.valueAsNumber/input_c.valueAsNumber;
    }
    }
    </script>
    <style>
    </style>
    <title>Example</title>
    </head>
    <body onload="">
    <form onsubmit="return false" oninput="
    Test();
    <!--o.value=input_a.valueAsNumber+input_b.valueAsNumber;-->
    ">

    <input name="input_a" id="input_a" type="number" step="any" value="" placeholder="Input A"></br>
    <input name="input_b" id="input_b" type="number" step="any" value="" placeholder="Input B"></br>
    <input name="input_c" id="input_c" type="number" step="any" value="" placeholder="Input C"></br>
    </br>
    <output name="o" for="a b c"></output>

    </form>
    </body>
[/code]

(*) Another possibility might be to have multiple outputs, but hide the ones which are not relevant (based on the inputs)...but how would I do that?

A: I got it to work, by using the Eval-function
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8"></meta>
<script>
function SelectFormula(){
if (input_a.valueAsNumber && input_b.valueAsNumber){
return "input_a.valueAsNumber+input_b.valueAsNumber";
} else if (input_b.value && input_c.value){
return "input_b.valueAsNumber*input_c.valueAsNumber";
} else if (input_a.value && input_c.value){
return "input_a.valueAsNumber/input_c.valueAsNumber";
}
}
</script>
<style>
</style>
<title>Example</title>
</head>
<body onload="">
<form onsubmit="return false" oninput="
o.value=eval(SelectFormula());
">
Input A: <input name="input_a" id="input_a" type="number" step="any" value="" placeholder="Input A"></br>
Input B: <input name="input_b" id="input_b" type="number" step="any" value="" placeholder="Input B"></br>
Input C: <input name="input_c" id="input_c" type="number" step="any" value="" placeholder="Input C"></br>
</br>
Output: <output name="o" for="a b c"></output>
</form>
</body>

I rather not use the Eval-function, but setting o.value=... directly in the function does not work :-(
