shin
shin

Reputation: 32721

How to submit by just selecting an option from a dropdown with jquery?

http://fsc.no/timeplan_rommen_197.html

When you select a different week (uke) from a dropdown on the right or trainer from the left dropdown above the schedule, it submit automatically . You don't need to click Submit(Vis).

How do you submit when you just select an option from a dropdown list?

Can it be done with jquery?

Thanks in advance.

Upvotes: 0

Views: 248

Answers (3)

Steven Spielberg
Steven Spielberg

Reputation:

Try this function:

$("#myddl").change(function(){
$("#myform").submit();
});

Upvotes: 0

Abdel Raoof Olakara
Abdel Raoof Olakara

Reputation: 19353

Yes you can submit a form using jquery code. in your case you need to submit the form when the user selects a new value in the drop down. this can be done as follows:

$('#dropdown-id').change(function() {
  $('#form-id').submit();
});

Upvotes: 0

Nick Craver
Nick Craver

Reputation: 630637

Yes, you can do by triggering the .submit() event, like this:

$("select").change(function() {
  $(this).closest("form").submit();
});

Or, call the native event:

$("select").change(function() {
  $(this).closest("form")[0].submit();
});

The above examples would make it happen with any <select> element, just give it a different selector like an ID, for example: $("#mySelect"), or a class if you have multiple, for example:

<select class="autoSubmit">

And bind it using:

$(".autoSubmit").change(function() { ...

Upvotes: 1

Related Questions