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?
 
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

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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.