Welcome to the Virtual Education Wiki ~ Open Education Wiki

Form:Test calculation form: Difference between revisions

From Virtual Education Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
<form>
<noinclude>
  <label for="num1">Number 1:</label>
This is the 'Calculation' form. The form is used to perform simple calculations.
  <input name="num1" type="number" />
</noinclude>
  <br>
<includeonly>
  <label for="num2">Number 2:</label>
{{{info|calculation form}}}
  <input name="num2" type="number" />
{{{for template|Calculation}}}
  <br>
Enter two numbers and select an operator below.
  <label for="operator">Operator:</label>
 
  <select name="operator">
{| class="formtable"
    <option value="+">Addition</option>
! Number 1:
    <option value="-">Subtraction</option>
| {{{field|number1}}}
    <option value="*">Multiplication</option>
|-
    <option value="/">Division</option>
! Number 2:
  </select>
| {{{field|number2}}}
  <br>
|-
  <input type="submit" value="Calculate">
! Operator:
  <br>
| {{{field|operator|input type=select|values=+,-,*,/}}}
  {{#ifexpr: {{{num1|0}}} AND {{{num2|0}}}
|}
    |Result:  
{{{end template}}}
    {{#switch: {{{operator}}}
 
      |+ = {{#expr: {{{num1}}} + {{{num2}}}}}
(You can see the form this query uses at [[Form:Calculation]], and the template it uses at [[Template:Calculation]].)
      |- = {{#expr: {{{num1}}} - {{{num2}}}}}
 
      |* = {{#expr: {{{num1}}} * {{{num2}}}}}
{{#ifexpr: {{{number1|0}}} AND {{{number2|0}}}
      |/ = {{#expr: {{{num1}}} / {{{num2}}}}}
| Result: {{#switch: {{{operator}}}
    }}
  |+ = {{#expr: {{{number1}}} + {{{number2}}}}}
  }}
  |- = {{#expr: {{{number1}}} - {{{number2}}}}}
</form>
  |* = {{#expr: {{{number1}}} * {{{number2}}}}}
  |/ = {{#expr: {{{number1}}} / {{{number2}}}}}
}}
}}
</includeonly>

Revision as of 13:46, 21 April 2023

This is the 'Calculation' form. The form is used to perform simple calculations.