How to select a form without submit button in drupal 8 using javascript

707 views Asked by At

I'm trying to use javascript to submit a select form without submit button. So far I think I'm close but it's not activating. Not quite sure why. This is the first time I'm tweaking drupal site.

<select data-drupal-selector="edit-field-campaign-vehicle-value" id="edit-    field-campaign-vehicle-value" name="field_campaign_vehicle_value" class="form-select">
<option value="All" selected="selected">- Any -</option>
<option value="event">Event</option>
<option value="local">Local</option>
<option value="national">National</option>
</select>

$( ".form-select" ).change(function() {});
2

There are 2 answers

0
Julio Silva On

You could use something like this

$( ".form-select" ).change(function() {   
    $('FORM-CLASS-OR-ID').submit() 
});
0
Daimos On

If your id is dynamic, you can also use:

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