I'm really feeling so tired as I'm writing this post. But that's not to stop me as I am very happy to have learned something new. While I was studying client's code, Converting from PHP to Java. I didn't quicly realize the how script.aculo.us and Prototype.js makes your javascripting life so much faster. HTML elements can be referred to by typing $("element") inside the <script></script> tags. And also form values using the $F("formelement").
Now the thing that made me jump with joy is how the Observer pattern is implemented in this framework. Take a look at the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <select name="intervalType" style='width: 100%'> <c:forEach var="interval" items="${intervalList}" varStatus="status"> <option value="${interval.intervalType}">${interval.intervalName}</option> </c:forEach> </select> <script language="JavaScript" type="text/javascript"> Event.observe('intervalType', 'change', checkIntervalChange, false);
function checkIntervalChange() { if ( $("intervalType").value == "${intervalList[3].intervalType}" ) { $("intervalStartDate").disabled = false; $("intervalEndDate").disabled = false; } else { $("intervalStartDate").disabled = true; $("intervalEndDate").disabled = true; } } </script> |
Isn't that very interesting? I hope you don't confuse JSP's Expression Language${} with Javascript's $(). :)