We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

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

TimMcAuley
TimMcAuley asked
on
Medium Priority
402 Views
Last Modified: 2008-03-17
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
Comment
Watch Question

Siva Prasanna KumarPrincipal Solutions Architect
CERTIFIED EXPERT
Top Expert 2006

Commented:
<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

Author

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 Architect
CERTIFIED EXPERT
Top Expert 2006

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

Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.