Question

I´m having this dropdownlistbox

<select name="ddlViewBy" id="ddlViewBy" style="width: 143px;">
        <option style="display:none" value="0">Add Song to Playlist</option>
        <?php foreach ($selothers as $rowsothers) {
            $addvideoname = $rowsothers['name'];
            $addvideoid = $rowsothers['id'];
            echo '<option value="'.$addvideoid.'">'.$addvideoname.'</option>';
        }
?> </select>

I also run a script that populates the < select > with new data when it is being clicked.

<script>
    $("select#ddlViewBy").click(function () {
        $.ajax({
            type: "POST",
            url: "getndata.php",
            cache: false,
            success: function (html) {
               $('#ddlViewBy').html(html);
            }
        });
    }); 
</script>

The ajax call works fine and I receive the new data onClick. Although when I choose an < option > it does the ajax call again and will therefore put the first < option > as the selected item.

Was it helpful?

Solution

I got it to work by extending the < select > with: onFocus="function()"

and putting the javascript in a function without the ".click"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top