aspose file tools*
The moose likes Struts and the fly likes Retrieving Variable from Javascript and Pass it to <s:hidden> then through the Actionclass. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Retrieving Variable from Javascript and Pass it to <s:hidden> then through the Actionclass." Watch "Retrieving Variable from Javascript and Pass it to <s:hidden> then through the Actionclass." New topic
Author

Retrieving Variable from Javascript and Pass it to <s:hidden> then through the Actionclass.

victor chiong
Ranch Hand

Joined: Apr 04, 2012
Posts: 73
I am using jquery struts2 grid plugin. I am using my own form to update, delete and insert object. I had created a hidden field to retrieved the value from javascript but it did not work... I also created a <s:textfield> it could not retrieve the value of the variable from javascript.. What seems to be the problem?

When I click the grid code below is activated.

var product_id = grid.jqGrid('getCell', sel_id, 'product_Id');

I want to pass the value of product_id to the hidden tag in struts2 by this.


document.getElementById('product_Id').value = product_id;


So it should pass the product_id value to product_Key field through this tag.

<s:hidden value="" name="product_Key" id="product_Id"/>


Then when i click the edit button on the grid, it should be passed as a paremeter through this lines.

<
s:url id="editurl" action="ProductUpdate">
<s:param name="product_Key"><s:property value="product_Key"/></s:param>
</s:url>

This is the edit click button.

Edit : {
title :'Edit record on the selected record on the row',
caption :'Edit Record',
icon:'ui-icon-pencil',
onclick: function(){ alert('Edit is clicked'),document.getElementById('product_Id').value = product_id,window.location = '%{editurl}' }
}






My Action Class

Ankit Dan
Ranch Hand

Joined: Aug 31, 2012
Posts: 47

the problem is struts tags are loaded first, quite astonished to see javascript code use jquery, much more easier
try $("#idofgrid").jqGrid('getGridParam', ....); to get grid params just a hint

Hope this helps
victor chiong
Ranch Hand

Joined: Apr 04, 2012
Posts: 73
I placed the hidden field at the bottom... nothing happend... hmm i need to check jquery raw.... im only using plugin which is easy.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Retrieving Variable from Javascript and Pass it to <s:hidden> then through the Actionclass.