I have two input fields, Id and Desc. I need a javascript which enters the values in second text field based on some of the fields already set. Like for christmas day, if 12/25 is entered, it should say Christmas day.
Its working for one value. But if I put “else if” its not working for multiple values.
<script type="text/javascript">
$(document).ready(function() {
$('#holidayDate').datepicker();
var availableTags = ["New years Day", "Martin Luther King Day", "Groundhog Day", "Valentine's Day", "Washington's Birthday", "Easter", "Earth Day", "National Arbor Day", "Mother's Day", "Memorial Day", "Flag Day", "Father's Day", "Independence Day", "Labor Day", "Columbus Day", "Halloween", "Veterans Day", "Thanksgiving Day", "Pearl Harbor Remembrance Day", "Christmas Day"];
$("#tags").autocomplete({source:availableTags});
$('#holidayDate').change(function() {
if ($(this).val().substring(0, 5) === '12/25') {
$('#tags').val('Christmas Day');
}else if ($(this).val().substring(0, 5) === '01/01') {
$('#tags').val('New years Day');
} else {
$('#tags').val('');
}
});
});
</script>
First, you can combine those into one DOM ready event. Also, some of your code was outside the event, so that’s probably why it wasn’t working.
UPDATE: Hopefully it’s just a poorly written example, but your given HTML is very invalid as well. Notice you are opening a
<div>tag and then closing a<p>tag, among other issues like not closing your<head>tag before opening the body, etc. All of these issues could be preventing the javascript from functioning properly.