JDev

Code, phpMarch 21, 2007 6:33 pm

Here is a compact function to convert HTML color to RGB:

function html2rgb($color){   
     return array(hexdec(substr($color, 0, 2)), hexdec(substr($color, 2, 2)), hexdec(substr($color, 4, 2)));
}

Code, jstl 1:56 pm

Here is an JSTL code example that shows how to build a select box that remembers the previous selection.

<select name=’days‘>
      <c:forTokens items="7;14;30;60;180; 365" delims=";" var="current">             
          <c:choose>
            <c:when test="${current==param.days}">
                      <OPTION selected>
                 </c:when>            
                 <c:otherwise>
                       <OPTION>
                 </c:otherwise>
             </c:choose>
               <c:out value="${current}" /></option>       
         </c:forTokens>
 </select>

Each iteration checks an option value against a request parameter that contains the value of the selected option element. If they are equal, the HTML option tag is given a selected attribute.

JSTL Books on Amazon.com 

Code, jstl 1:03 pm

Here is a simple example that shows how to populate Javascript array values from JSTL iteration tags:

<script type=’text/javascript’>
    var arr = new Array();
    <c:forEach begin="1" end="5" var="current">
        arr.push(<c:out value="${current}" />);
    </c:forEach>   
</script>

The Javascript arr array now contains values from 1 to 5.

JSTL Books on Amazon.com