aspose file tools*
The moose likes Struts and the fly likes how to set javascript varibale in <s:url><s:param> value attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to set javascript varibale in <s:url><s:param> value attribute" Watch "how to set javascript varibale in <s:url><s:param> value attribute" New topic
Author

how to set javascript varibale in <s:url><s:param> value attribute

T Ponraj
Greenhorn

Joined: Nov 07, 2007
Posts: 21
hi All,

I m struggling to set javascript variable in s:param value attribute

Here is my code

java script variable.

var contorlName=1;

acridsDiv = document.getElementById("acrids");
acridsDiv.href ='<s:url id="acrid_url" action="SearchAcridAction" namespace="/problemrecord">' +
'<s:param name="acridTypeIdAjax" value="1">' +
'</s:param> </s:url>';

I want to set controlName varibale in to value attribute, Tried with ' and "" , any help would be appreciated.



Regards
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Leaving the debate about whether or not this is the best way to go about this aside, you need to create the URL independent of the JS, then use the value in the JS. The <s:url> tag allows you to specify the var in which to store the results--use it, and the <s:property> tag, in combination.
T Ponraj
Greenhorn

Joined: Nov 07, 2007
Posts: 21
Hi David, Many thanks for the help.

Could you please provide me the sample code to use it.

I have tried it, but could not get achive it.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

...
T Ponraj
Greenhorn

Joined: Nov 07, 2007
Posts: 21
Thanks for the help, I m still struggling bcos I m new to Struts.

Here is my code.

<s:url id="acrid_url" action="SearchAcridAction" namespace="/problemrecord">
<s:param name="acridTypeIdAjax" value="1">'
</s:param> </s:url>




Javascript
var contorlName=<<method parameter which is coming from my Jsp Onclickevent>>;

How do I set my controlName variable in to <s:param value attribute. So that it pass this param to my action class.

var jsVar = <s:property value="#foo"/>';




David Newton wrote:...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That will be more difficult: JSP runs on the server side, JavaScript runs on the client side. The S2 tags are rendered before any JavaScript executes.

You might need to just build your URL by hand, although in general such things can be worked around by building a URL for each (whatever it is you're iterating over).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to set javascript varibale in <s:url><s:param> value attribute