Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to write my own layerswitcher because I want a dropdown box (and later a second one)

My Webinspector says: Uncaught TypeError: Cannot read property 'value' of undefined but I cannot find what is wrong. In my opinion it is defined. Thanks to everyone trying to help me.

Here is the code:

<div id="map"></div>
<!--<div id="external_control"style="font-size:16px; padding:10px;border:1px solid black;background-color:grey;width:250px;height:100px;"></div>-->
<script>
    function auswahlLayer1(element){
             if(element.value == "Einwohner"){
                overlayEnergieverbrauch.setVisibility(false);
                overlayEinwohner.setVisibility(true);
             }
             if(element.value == "Energieverbrauch"){
                overlayEinwohner.setVisibility(false);
                overlayEnergieverbrauch.setVisibility(true);
             }
    }
</script>
<div id="control" >
<select onchange="auswahlLayer1()">
        <option value="Einwohner">Einwohner</option>
        <option value="Energieverbrauch">Energieverbrauch</option>
</select>

share|improve this question

2 Answers 2

up vote 0 down vote accepted

Take a closer look:

<select onchange="auswahlLayer1()">

You are calling auswahlLayer1() without any parameters (therefore, element is undefined and element.value throws error). Try

<select onchange="auswahlLayer1(this)">
share|improve this answer
    
Thank you for your answer, ist was the first part to my solution. I worked on that part but now i have the next error :-( –  CST Oct 3 '13 at 9:11

I changed a few things but now I have another problem. The Webinspector says auswahlLayer1 is not defined. I don't understand it because I believe I have defined it, the code now looks like this :

<script>
    function auswahlLayer1(element){
            document.getElementById("Einwohner")setVisibility(false);
            document.getElementById("Energieverbrauch").setVisibility(false);
            var value = element.options[element.selectedIndex].value; 
             if(value == "Einwohner"){
                console.log("Einwohner");
                document.getElementById("Einwohner").setVisibility(true);

             }
             if(value == "Energieverbrauch"){
                document.getElementById("Energieverbrauch").setVisibility(true);
             }
            }
    </script>
    <div id="control" >
    <form action="select.htm">
        <select name="Auswahl1" size="1" onchange="auswahlLayer1(this)">
            <option value="Einwohner">Einwohner</option>
            <option value="Energieverbrauch">Energieverbrauch</option>

        </select>
    </form>
    </div>
share|improve this answer
    
You should post this as separate question. And also you should add point behind ("Einwohner") and setVisibility :) –  user1702401 Oct 3 '13 at 10:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.