0

I'm pretty new to programming, I'm trying to get the user input of the options from "province" and the value from "income" and use it in the js function below, but I can't figure out what's wrong.

<div class="taxform">
  <form>
    <label for="province">Please select your province from the list below: </label>
    <select id="province" name="province">
      <option value="0">Select option</option>
      <option value="1">Newfoundland and Labrador</option>
      <option value="2">Prince Edward Island</option>
    </select>
  </form>
  <form>
    <label for="income">Please enter your annual income: </label>
    <input type="number" value="" id="income" name="income">
    <br> <br>
    <button onclick="calculate(document.getElementById('province').value,document.getElementById('income').value)">Calculate</button>
  </form>
function calculate() {
  var percentage;
  var province = province(document.taxform.province.value);
  var income = income(document.taxform.income.value);
  if province = 1 {
    percentage = 20;
  }
  else if province = 2 {
    percentage = 30;
  }
  var res = (income - ((percentage / 100) * income));
  alert(res);
}
Phil
  • 157,677
  • 23
  • 242
  • 245
Nexius
  • 1
  • 1
  • You're passing two parameters to `calculate()` but it doesn't accept any. You're also calling two undefined functions... `province()` and `income()`. Finally, add `type="button"` to your ` – Phil Feb 07 '22 at 03:39
  • I think you should remove form tag and edit scripts var province = document.getElementById('province').value; var income = document.getElementById('income').value; – Mai Truong Feb 07 '22 at 03:48
  • @Phil thanks a lot for pointing out my basic mistakes, it's working as intended now – Nexius Feb 07 '22 at 07:44

0 Answers0