Javascript global resetting -


i new javascript have read , got following problem: created global var, i'm setting in function , i'm trying call in function comes out undefined. i've googled around , seems it's called javascript hoisting decleration. can't find solution on this. code.

<script type="text/javascript"> var value; function getcombobox() {     var value = document.getelementbyid('vereniging').value;     console.log(value); } function ischanged() {     console.log(value);     var chboxs = document.getelementbyid('checkbox');     var show = document.getelementbyid('hidden');     if(chboxs.checked && value=='bni') {     show2.style.display= 'block';     show.style.display='none';     }     if(chboxs.checked && value=='wtc') {         show2.style.display='none';     show.style.display='block';     } } </script> 

it sets correctly first function.

var value = document.getelementbyid('vereniging').value; 

you declaring new variable instead of writing global one.

if want use global, remove var.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -