Reputation: 123
I have two date inputs & one drop down with first option "All"..
My problem is when I select dates, if both dates are same, then the first option of select should become blank.
<script type='text/javascript'>
jQuery(document).ready(function () {
var first = jQuery('#category').find('option').first();
jQuery('#date_to').on('change', function (e) {
if($('#date_to').val == $('#date_from').val) {
first.remove();
})
});
</script>
Upvotes: 2
Views: 705
Reputation: 749
As you want to remove first option you are required to put on change on both date pickers because user can pick any date and every time a user picks a date condition is executed. Well that is up to your need also.
Following is the working code.
<script type='text/javascript'>
jQuery(document).ready(function () {
var first = jQuery('#category').find('option').first();
$('#date_to').on('change', function (e) {
remove();
});
$('#date_from').on('change', function (e) {
remove();
});
function remove () {
if($('#date_to').val() == $('#date_from').val()) {
first.remove();
};
}
});
</script>
Upvotes: 2
Reputation: 3830
Change val
to val()
because it is a method. You also need to move the )
of the if
statement to the correct place;
if ($('#date_to').val() == $('#date_from').val()) {
first.remove();
}
Upvotes: 4