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

Hello,

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 ?

Thanks,
T
TimMcAuleyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
<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.

check

http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=50&t=011162
TimMcAuleyAuthor Commented:
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 ?

T
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
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() > ');" / >

or

<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.
:-)

fargoCommented:
Hi,

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.

or

<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" %>

fargo

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.