Reputation: 35
I am having difficulty trying to create a new div using javascript from a form. I have a select box in my html form;
<select name="seasonSelector" id="seasonSelector" onchange="jsSeason('seasonWrapper')">
My seasonWrapper is a div which contains the whole content and onChange I am using a Javascript function to create a new div but having difficulty.
function jsSeason(divname) {
var x = document.getElementById('seasonSelector');
if(x = 2) {
var newDiv = document.createElement('div');
document.getElementById(divname).appendChild(newDiv);
}
}
Not really sure what it is i'm doing wrong or not including in my code.
Thanks in advance.
Upvotes: 1
Views: 74
Reputation: 193261
x
is select element, you want yo read its value:
if (x.value == 2) {
// ...
}
Also note, that you should use comparison operator ==
instead of assignment =
.
Upvotes: 2