Evaluating <%= fieldName.toString() >  from within onblur

Posted on 2006-04-01
Last Modified: 2008-03-17

I have a JSP file and I want to do validation in JavaScript using onblur().

For the validation I need to pass the JavaScript a variable called fieldName.
fieldName is defined as:
< bean:define id="fieldName" name="staticDataItemList" property="name" />

The JavaScript method which is doing the validation is called printAlerts.

To call the JavaScript validation I am using the line:
<html:text name="staticDataItemList" property="value" size="50" onblur="printAlerts(' <%= fieldName.toString() > ')" / >

I was hoping that when that the resulting HTML would have the actual field name as an argument for printAlerts, i.e. if the value of fieldName was itemName, the HTML would look like:
< input type="text" name="staticDataItemList[3].value" size="50" value="" onblur="printAlerts('itemName')" />

Instead the resulting HTML is :
< input type="text" name="staticDataItemList[3].value" size="50" value="" onblur="printAlerts(' < %= fieldName.toString() %> ')" />

Can anyone solve this problem please ?

Question by:TimMcAuley
    LVL 23

    Expert Comment

    <html:text name="staticDataItemList" property="value" size="50"
    onblur="printAlerts(' <%= fieldName.toString() %> ')" / >

    i don't see any thing wrong.But you may try using a bean:wrtie instead of <%= %> statement.


    Author Comment

    Thank you for replying.

    I tried what you suggested (using bean:write instead).  That didn't work either.
    The code I tried was :
    <html:text name="staticDataItemList" property="value" size="50"
    onblur="printAlerts('<bean:write name="fieldName"/>')"/>

    The output of this was:
    < input type="text" name="staticDataItemList[3].value" size="50" value="" onblur="printAlerts('<bean:write name="fieldName"/>')" />

    Is there anything else I could try ?

    LVL 23

    Expert Comment

    ok tel me some thing what kind of object is that field name is it a string object or is it some thing else.

    and one more thing just check if there is some java script error

    becasuse there is a semicolon missing in java script function call.

    <html:text name="staticDataItemList" property="value" size="50" onblur="printAlerts(' <%= fieldName.toString() > ');" / >


    <html:text name="staticDataItemList" property="value" size="50"
    onblur="printAlerts('<bean:write name="fieldName"/>');"/>

    i think this should solve it, if not please get back.

    LVL 11

    Accepted Solution


    The following is required to make it work

    <html:text name="staticDataItemList" property="value" size="50" onblur="printAlerts(" <%= fieldName.toString() >");" / > // take a look a ' is replaced with "

    // in javascript anything between ' is considered as string.


    <html:text name="staticDataItemList" property="value" size="50"
    onblur="printAlerts("<bean:write name="fieldName"/>");"/>        // the same here

    Moreover for the bean:write to work u need the html bean tag to be in the taglib directive (if u are using struts) like the following

    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Title # Comments Views Activity
    JTable - RowFilter & Columns Header. 3 129
    Can I clean log of  running tomcat 7 server ? 3 108
    servlet concurrency 13 79
    maven set up 2 84
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
    The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now