java - passing conditional spring mvc parameters into javascript url function -
i have javascript calendar control in spring mvc application. when user clicks on date in calendar control, user redirected detail page date. problem want pass other parameters in url in addition date. how add other parameters url in javascript functionality?
here javascript creating url 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 illustration, here code generating url including 2 other optional parameters (pid , eid) elsewhere in 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 alter javascript above adds parameters pid , eid if , if either pid or eid not null?
this can done concatenating url parameters separated & character:
var url = "${pagecontext.request.contextpath}/calendar?day=" + encodeuricomponent(datetext); if (pid) { url += "&pid=" + encodeuricomponent(pid); } if (eid) { url += "&eid=" + encodeuricomponent(eid); } window.location = url;
Comments
Post a Comment