0

I have an MVC View (https://mydomain/Data/MyChart) that contains a dropdownlist where the onchange event triggers an ajax call to get data to populate a chart. This is working perfectly.

I now want to add the functionality whereby I could call this view and pass the item to select via a querystring parameter. https://mydomain/Data/MyChart?station=ChartA

When doing this, I can retrieve the querystring value, and successfully set the item selected in the dropdownlist, however the onchange event does not triggered so the chart is not generated.

What am I missing?

.NET Fiddle to demo selecting dropdown and getting value in change event https://dotnetfiddle.net/uZi8LU

.NET Fiddle demonstrating setting a value (querystring) to set the selected item and onchange NOT triggered: https://dotnetfiddle.net/kCJMC4

1 Answer 1

0

Your new functionality pre-loads the page with a selected value, so the element it is not changed after the document is ready (for the pre-loaded value). The new functionality requires a once-off ajax call immediately once the document is ready:

    <script type="text/javascript">
        $(document).ready(function () {
            alert($("#StationGroup option:selected").text());

            //  StationId Dropdown change function
            $("#StationGroup").change(function () {
                alert($("#StationGroup option:selected").text());
            });         
        });
    </script>
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.