Home Ask Login Register

Developers Planet

Your answer is one click away!

Pieter Schreurs February 2016

Javascript global resetting

I am somewhat new to Javascript have read some into it and got the following problem: I created a global var, i'm setting it in a function and i'm trying to call it in another function but it comes out as undefined. I've googled around and it seems it's called Javascript Hoisting Decleration. But i can't find the solution on this. This is my code.

<script type="text/javascript">
var value;
function getComboBox() {
    var value = document.getElementById('vereniging').value;
function isChanged() {
    var chboxs = document.getElementById('checkbox');
    var show = document.getElementById('hidden');
    if(chboxs.checked && value=='BNI') {
    show2.style.display= 'block';
    if(chboxs.checked && value=='WTC') {    
} </script>

it sets correctly with the first function.


Qwertiy February 2016

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

You are declaring a new variable instead of writing into global one.

If you want to use global, remove var.

Post Status

Asked in February 2016
Viewed 2,401 times
Voted 9
Answered 1 times


Leave an answer

Quote of the day: live life