In my Spring MVC application, I have implemented a JavaScript calendar control that redirects the user to a detail page for a selected date. However, I am facing an issue where I need to include additional parameters in the URL along with the date. How can I modify the JavaScript functionality to add these parameters when necessary?
Below is the JavaScript code snippet that currently generates the URL with only the date parameter:
<script type="text/javascript">
$(document).ready(function() {
$("#dayPicker").datepicker({
firstDay: 1,
dateFormat: "yy-mm-dd",
defaultDate: new Date(${calendar.dayMillis}),
onSelect: function(dateText, instance) {
window.location = "${pageContext.request.contextPath}/calendar?day=" + encodeURIComponent(dateText);
}
});
});
</script>
For reference, here's a section of code from the JSP that demonstrates how to generate a URL with additional parameters (pid and eid) if they are not null:
<c:url var="previousLink" value="/calendar">
<c:param name="day" value="${calendar.previousDay}" />
<c:choose>
<c:when test="${pid!=null}">
<c:param name="pid" value="${pid}" />
</c:when>
<c:otherwise></c:otherwise>
</c:choose>
<c:choose>
<c:when test="${eid!=null}">
<c:param name="eid" value="${eid}"></c:param>
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
</c:url>
<a href="${previousLink}">Previous</a>
How can I adjust the JavaScript above to include the pid and eid parameters in the URL only if they are not null?