Reputation: 180
I am trying to pass data from form into JavaScript variables but I am having an issue, Errors are listed below.
<div>
<form>
<select id="month" name="month">
<option value="11">11</option>
</select>
</form>
</div>
<button onclick="calculate()"></button>
<script>
function calculate() {
var countMonth = document.getElementById(month).value;
alert(countMonth);
}
Error: Uncaught TypeError: Cannot read property 'value' of null at calculate (DateTracker.html:81) at HTMLButtonElement.onclick
Upvotes: 0
Views: 51
Reputation: 15268
You need to quote strings:
document.getElementById('month')
What you have will try to retrieve variable month
, which should be your select DOM element.
Upvotes: 1