• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to call javascript function from struts tag

 
lydia edward
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a requirement like,I have to call a javascript function on onchange event of drop down box.
<tr>
<td height="20" align="center"><s:select label="Type* " id="groupType" cssStyle="width:125px" list="groupTypeMap"
name="group.groupType" onchange="javascript:enableOrDisableParentGroup();return false;" /></td>
</tr>


but here it is not calling the javascript method.

When I am directly giving alert() messages there itself it is working like:
<tr>
<td height="20" align="center"><s:select label="Type* " id="groupType" cssStyle="width:125px" list="groupTypeMap"
name="group.groupType" onchange="javascript:alert('ALERT MESSAGE');" /></td>
</tr>

Can you please tell me what is the exact way to call javascript function from struts tags.

Thanks
Lydia
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lydia, use code tags it looks as good as below, easy to read and very simple to do it... isnt it?

Anyways, try removing "return false;" and just try as below,
 
lydia edward
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the way you told but still it didn't work.
Can you please suggest me more ways.
 
mahesh shinde
Ranch Hand
Posts: 69
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paste your javascript function here
and check for any parameters it takes.
 
lydia edward
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same issue I am facing here also.

<s:a id="url2" href="%{deleteUrlTag}" executeScripts="true" onclick="return confirm('Do you really want to delete this Remote machine?');" >Delete</s:a></td>

This is struts anchor tag.I am calling javascript confirm() message.When user click on yes then it should call the href url else in case of cancel it will not do anything. This tag is working fine.

But in place this I have to use struts dojo anchor tag because in that only I can specify the targets attribute.
so when I am trying with this:

<sx:a id="url2" href="%{deleteUrlTag}" executeScripts="true" onclick="return confirm('Do you really want to delete this Remote machine?');" >Delete</sx:a></td>

It is showing the confirm box, but in both the cases ok and cancel it is calling the href url.

1>For struts dojo tags is there different procedure to call the javascript function.
2> how can we call a seperate javascript function on these anchors onclick events.

Please help me on this.
Thanks in advance.



 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure about the "struts dojo tags" but there is no dependency among the action attributes href and onclick that are being used. They are working as they should.
May be you can do one thing.
Instead of having a confirm directly, call a javascript function which has it and drive the href based on user confirmation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic