Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with html.text and onblir

 
Trish Hartnett
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Stefan Evans
Bartender
Pie
Posts: 1671
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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

Best Regards,
Trish.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic