?
Solved

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

Posted on 2006-04-01
4
Medium Priority
?
389 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
0
Comment
Question by:TimMcAuley
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16352765
<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
 

Author Comment

by:TimMcAuley
ID: 16353750
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
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16354250
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
 
LVL 11

Accepted Solution

by:
fargo earned 2000 total points
ID: 16354466
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Applications for our next round of the Experts Exchange Scholarship Contest are starting to roll in. It made us wonder what our past winners are up to these days. Here's a look at what four winners experienced with the contest and what they're doing…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview
Suggested Courses

840 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