You need to quote strings:
document.getElementById('month')
What you have will try to retrieve variable month
, which should be your select DOM element.
Solution 1 :
Problem :
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
Comments
Comment posted by en.wikipedia.org/wiki/JScript
JScript would refer to Microsoft’s
Comment posted by EKrol
Sorry SO didn’t let me reply prevously, thank you for pointing out the error!