File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Not able to call javascript function from struts tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Not able to call javascript function from struts tag" Watch "Not able to call javascript function from struts tag" New topic
Author

Not able to call javascript function from struts tag

lydia edward
Greenhorn

Joined: Feb 02, 2011
Posts: 11
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

Joined: Jan 30, 2011
Posts: 329

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,


Have Fun with Java
little,little.. little by little makes a lot..
lydia edward
Greenhorn

Joined: Feb 02, 2011
Posts: 11
I tried the way you told but still it didn't work.
Can you please suggest me more ways.
mahesh shinde
Ranch Hand

Joined: Jul 24, 2009
Posts: 69

Paste your javascript function here
and check for any parameters it takes.
lydia edward
Greenhorn

Joined: Feb 02, 2011
Posts: 11
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

Joined: Jan 30, 2011
Posts: 329

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to call javascript function from struts tag