This input select field is generated dynamically, the options will change depending on what the user has selected in the previous fields.
<select name="vehicle">
<?php $loop = new WP_Query( array( 'post_type' => 'fleet') ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<option class="vehicle-option" value="<? the_title() ?>" <?= $_POST["vehicle"] == the_title('', '', false) ? "selected" : "" ?>>
<?php the_title(); ?>
</option>
<?php endwhile; wp_reset_query(); ?>
</select>
And because these options have been generated dynamically, I’m unable to select that field with Jquery. (I can select it with CSS but I need to apply validation to this field because it's a required field that the user has to select).
The code below won't select it, I’ve also tried adding ID and class tags to and around the field but they all failed.
$('select[name=vehicle]’)………
Because eventually I want to be able to select the options inside this field as well;
$('select[name=vehicle]').change(function(){
if($("select[name=vehicle] option:selected").val() !== "Vehicle preference"){
//run function
}
else{
//run function
}
}