I have a javascript calendar control in a spring mvc application. When the user clicks on a date
in the calendar control, the user is redirected to a detail page for that date. The problem is that I want to pass other parameters in the url in addition to just the date
. How do I add other parameters to the url in the javascript functionality?
Here is the javascript for creating the url with only the date
as a 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 illustration, here is the code for generating a url including two other optional parameters (pid
and eid
) elsewhere in the JSP:
<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 do I alter the javascript above so that it adds parameters for pid
and eid
if and only if either pid
or eid
is not null
?