tags:

views:

518

answers:

2

I've got a simple MVC view with a dropdown and a Submit button that posts the form and uses the value of the dropdown to change the view ("values" is populated in the controller):

<% Using Html.BeginForm()%>
<%=Html.DropDownList("values", "No value")%>
<input type="submit" value="Submit" />
<%--rest of page here--%>
<% End Using%>

How can I set this up to change once the dropdown is changed, i.e. eliminate the Submit button?

+4  A: 

You can use the onchange event to submit the current form:

<%=Html.DropDownList("values", ViewData["ListData"],
                      new { onchange="this.form.submit();" })%>
CMS
+3  A: 

I would use jquery to make the change

first add the class to your submit button and dropdown list as so:

     <%=Html.DropDownList("values", "No value",new {_class="dropdown"})%>

      <input type="submit" value="Submit" class="submit"/>

then use jquery like this:

  $(document).ready(function() {

   $(".dropdown").change({

   $(".submit").hide();
    })
  });
TStamper