Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142188

Accessing option value

$
0
0

I'm using PHP to list all sub-directories in gallery folder:

<div class="dropdown-gallery" id="dropdown-gallery" onchange="changeGallery(this)">
            <select>
                <?php
                $galleries = scandir("./gallery");
                foreach($galleries as $gallery){
                    echo("<option value='$gallery'>$gallery</option> ");
                }
                ?>
            </select>
        </div>

I would like to operate on values of those optinos in JS, the problem is that this code:

<script>
function changeGallery(elem){
    alert(elem.options[elem.selectedIndex].value);
    alert(elem.value);
}

Returns Uncaught TypeError: Cannot read property 'undefined' of undefined in both alert cases
I was looking for a solution and found nothing that could help me


Viewing all articles
Browse latest Browse all 142188

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>