简体   繁体   中英

How to use javascript function in jstl if condition

This is my javascript function:

function isEmpty(field){
    if( document.getElementsByName(field).value === '' )
        return true;
    return false;
}

How to use my javascript function in jstl here:

<c:choose>
    <c:when test ="isEmpty(firstName)">
        <span class="red">please-fill-required-fields</span>
    </c:when>
    <c:otherwise>
        <span class="red"> </span>
    </c:otherwise>
</c:choose>

Jstl codes execute on server side and javascript functions execute after rendering the page by server! So, you can't use javascript inside jstl code. Instead, you should use jstl(not javascript) for checking null value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM