Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit form on change of dropdown

I'm using MVC 3 and razor and have a form in which there is a dropdown. How do I submit the form when the value in the dropdown changes? I have no submit button.

@using (Html.BeginForm())
{
...

<div class="row">
                    <label>
                        Type of Card</label>
                    <div class="item">
                        @Html.DropDownList("PaymentFormModel.CardType", cardTypes, new { required = "required" })
                    </div>
                </div>
...
}
like image 816
Sachin Kainth Avatar asked Feb 18 '23 23:02

Sachin Kainth


1 Answers

Try like this

@Html.DropDownList("PaymentFormModel.CardType", cardTypes, new { required = "required", @onchange="submitform();" })

Here is the script for it:

function submitform()
{
  $('form').submit();
}

hope it helps

like image 170
Karthik Chintala Avatar answered Mar 07 '23 04:03

Karthik Chintala