javascript - ignore value of select option jQuery -
javascript - ignore value of select option jQuery -
this quite simple wondering how ignore value option select
if equal value, illustration have select
<select> <option value="">all</option> <option value=".dog">dog</option> <option value=".cat">cat</option> </select> $('select').on('change', function() { var animal_type = $('option:selected').text(); });
so if 'all' selected not want assign animal_type
variable in next ajax post animal_type
disregarded , not sent parameter
$.ajax({ type: 'post', url: '/public/rehomed', data: { animal_type: animal_type, #so if selected should not passed through rehomed: false, } });
the reason thinking remove animal_type
variable ajax post parameters of post create sql query on server side me in rails.
add status check value of selected alternative before ajax.
$('select').on('change', function() { var animal_type = $('option:selected').text(); var data_send = {animal_type: animal_type, rehomed: false,}; if(animal_type != "all"){ data_send = {rehomed: false,}; } $.ajax({ type: 'post', url: '/public/rehomed', data: data_send, }); });
javascript jquery
Comments
Post a Comment