aspose file tools*
The moose likes Struts and the fly likes problem with html.text and onblir Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "problem with html.text and onblir" Watch "problem with html.text and onblir" New topic
Author

problem with html.text and onblir

Trish Hartnett
Greenhorn

Joined: Apr 29, 2003
Posts: 18
I'd really appreciate if somebody could help me with this problem , it is
really driving me up the wall.

I have a JSP file and I want to do validation in JavaScript using onblir().
[I'm replacing the letter "u" with the letter "i" here as UBB (the forum engine tha tJavaRanch runs on) won't allow posts with on blur in them. So every where you see onblir this should actually be onblXr.]

For the validation I need to pass the JavaScript a variable called
fieldName.
fieldName is defined as:
& lt; bean efine id="fieldName" name="staticDataItemList" property="name"
/& gt;

To call the JavaScript validation I am using the line:
& lt; html:text name="staticDataItemList" property="value" size="50"
onblir="printAlerts(' & lt; %= fieldName.toString() % & gt ')" /& gt;

I was hoping that when that the resulting HTML would have the actual field
name as an argument for printAlerts, i.e. the HTML would look like:
& lt; input type="text" name="staticDataItemList[3].value" size="50"
value="" onblir="printAlerts('fItem')" /& gt;

where fItem is the value of fieldName.

Instead when I load the JSP in the browser I get :
& lt; input type="text" name="staticDataItemList[3].value" size="50"
value="" onblir="printAlerts(' & lt; %= fieldName.toString() % & gt ')"
/& gt;

Can anyone suggest anything please ?

Thanks,
Trish.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Although you can use scriptlets in an <html:text> tag, the rule is "all or nothing", meaning that the entire attribute must be a scriptlet, or none of it must be a scriptlet.

Bearing this in mind, the following should work:

<html:text name="staticDataItemList" property="value" size="50" onblir='<%="printAlerts("+fieldName.toString()+")">' />
[ April 02, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
alternatively, you could use the javascript keyword 'this'

<html:text name="staticDataItemList" property="value" size="50" onblir="printAlerts(this)" />

and then your javascript function:

function printAlerts(target){
var fieldName = target.name;

}
Trish Hartnett
Greenhorn

Joined: Apr 29, 2003
Posts: 18
Hello,

thank you for your replies. Merrill's suggestion works great for what I want to do thanks.

Best Regards,
Trish.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with html.text and onblir
 
Similar Threads
Capture value in the onclick event
Trying to evaluate lt%= fieldName.toString() gt from with an onblir
How do I change Parameter in servlet?
session management problem with iframes
JS function called from JSP works fine in FireFox won't work in IE