I have a select HTML and change the value of a variable after it passes the onchange () function. The problem is that I have another condition and I can not validate.
JS:
//function mode select
var option = 0
function getData(val) {
if (val.value === "option1"){
option = 1
alert("option deplacement!");
}else{
option = 2
alert("option ligne!");
}
show();
}
function show() {
console.log(this.option);
val = this.option
if (val == 2){
var el = document.getElementById('id_click');
el.onclick = function (e) {
alert("click2")
var ev = e || window.event;
var x2 = el.getAttributeNS(null, "x");
var y2 = el.getAttributeNS(null, "y");
//console.log(x2+" "+y2)
}
}
}
HTML:
<select id="selectid" onChange="getData(this);" >
<option value="option1">Deplacement</option>
<option value="option2">lignes</option>
</select>
<div id="id_div">dfsd</div>
Example on Jsfiddle