Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7195021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:29:43+00:00 2026-05-28T20:29:43+00:00

I have a dropdown list that auto submits a form and performs a search

  • 0

I have a dropdown list that auto submits a form and performs a search that I use throughout a project via a partial view, but it only works the first time I use it, unless I refresh the page. It’s an MVC 4 with jQuery Mobile project.

Here is the code I have in my partial view,

<script type="text/javascript">
    $(function () {
        $("#CoastLineID").change(function () {
            var actionUrl = $('#TheForm').attr('action') + '/' + $('#CoastLineID').val();
             $('#TheForm').attr('action', actionUrl);
             $('#TheForm').submit();
         });
    });
</script>
<p>
    @using (Html.BeginForm("SearchCoast", "Home", FormMethod.Post, new { id = "TheForm" }))
    {
        @Html.DropDownList("CoastLineID", (SelectList)ViewBag.ArticleId, "Select a Coastline")
    }
</p>

I guess I need to be able to refresh the page or the list each time a page/view that uses the partial view is loaded somehow. Is this a jQuery issue???

Any ideas, I can put the URL up for the site if I’m allowed to?

Update/Edit

Thanks guys,

I’ve come across a few issues mixing jQuery Mobile and MVC and mostly due to the way they both handle URL strings differently, all coming from 15 years of web development. All the jQuery Mobile docs deal with classic URL strings e.g.. about/us.html which is not the MVC way!

This is my controller code to populate the dropdown,

var coastlines = db.CoastLines.Select(c => new { c.CoastLineID, c.CoastLineName });
ViewBag.CoastLineId = new SelectList(coastlines.AsEnumerable(), "CoastLineID", "CoastLineName", 0);

And this is the web site,

http://www.peninsulaguide.com.au/

Click “Beach Search” and then “Select a Coastline” or “Select a Town” will work but nothing after that without a refresh.

There are two dropdowns but it doesn’t make a difference if I remove one.

Cheers,

Mike

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:29:44+00:00Added an answer on May 28, 2026 at 8:29 pm

    It’s hard to tell for sure without seeing the entire page, but a likely cause of your problem is that the dropdownlist on the part of the page which is reloaded when the form is posted.

    If that is so, your problem is that you are hooking up an event handler to one dropdownlist, and then expects that event handler to handle change events from all later dropdownlists that are given the same id.

    Read up on the .live() method in the jQuery documentation, and then change your code to this:

    $(function () {
        $("#CoastLineID").live('change', function () {
            var actionUrl = $('#TheForm').attr('action') + '/' + $('#CoastLineID').val();
             $('#TheForm').attr('action', actionUrl);
             $('#TheForm').submit();
         });
    });
    

    Note: If you’re using jQuery 1.7 or later, .live() is deprecated and should be replaced by .on(). To accomplish this, replace

    $("#CoastLineID").live('change', function () { ... });
    

    with

    $(document).on('change', '#CoastLineID', function () { ... });
    

    Details can be found in the documentation for .live(). Thanks to stian.net for pointing this out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that populates a Drop Down List and auto submits
I have a dropdown list that stores name/value pairs. The dropdown appears in each
I have a dropdown list with a piece of code that is run when
I have a dropdown list that is currently populated from a result set of
I have a dropdown list that I am binding to a datatable. Here is
I have a dropdown list that contains a series of options: <select id=SomeDropdown> <option
I have a drop down list that has options that need to be passed
I have a drop down list that triggers an updatepanel when the index is
I'm using classic asp, I have a drop down list that the user selects
I have about 10 drop down list controls that get populated. Instead of copying/pasting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.