0

Hello stackoverflow people, i've been coding for sometime and got stuck with this script. Because i cant find out why im getting console error:

TypeError: document.getElementById(...) is null


var Nlang = document.getElementById('langSelect').value;

ive tried doing as function onchange and ve tried this:

document.getElementById('langSelect').onchange = function() {

But that didnt worked too. What is wrong with this script, here is my javascript code:

function WasChanged(){
    var Nlang = document.getElementById('langSelect').value;
    var currentUser = <?php echo json_encode($AppUI->user_id); ?>;
};

And here is my php code:

    echo arraySelect($langlist, 'pref_name[LOCALE]', 'onchange="WasChanged()" class="text" size="1"', $userLang, true);

enter image description here

7
  • Add the HTML source too. Commented Aug 3, 2015 at 6:54
  • echo arraySelect($langlist, 'pref_name[LOCALE]', 'onchange="WasChanged()" class="text" size="1"', $userLang, true); This is the code witch creates the html with select Commented Aug 3, 2015 at 6:55
  • 1
    It is not the html source. It is the script that generates the html. Commented Aug 3, 2015 at 6:57
  • where is this id langSelect in your html? Commented Aug 3, 2015 at 6:58
  • I updated, in the picture there is the code Commented Aug 3, 2015 at 7:00

1 Answer 1

2

If document.getElementById('langSelect') returns null, there must not be a div with that ID in the Dom.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.