• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

pass value from javascript to strutsaction class

 
naresh kumar k
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi every one ,
I am new to javascript. In my project i am trying to call struts action method from javascript every thing goes fine but i am unable to get values from corresponding form class.

here is my jsp page:


in my action class :


Actually i am trying to set remaining fields in the page on loose focus of productName field.

Here exactly what i need is" productsForm.getProductName()" should return the data entered in jsp page.

I don't know whether this is correct approach or not,if not please correct me.

waiting for the reply

with regards
naresh kumar k

 
Akhilesh Trivedi
Ranch Hand
Posts: 1603
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
form-bean and action-mappings are properly configured in struts-config.xml. Especially form-beans.

You must have getters and setters in your form.


What are you trying to do at line 6?
 
naresh kumar k
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Akhilesh Trivedi,
thanks for the reply. I am pretty confident that action mappings are correct and getters and setters are there in my form.

In line 6 "document.forms[0].action="CSProductsAction.do?products=fillDetails"; "
CSProductsAction is form name and products is parameter and fillDetails is method in action class
Actually i am trying call action class method using onblur() .

waiting for your reply

with regards

naresh kumar k
 
Akhilesh Trivedi
Ranch Hand
Posts: 1603
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
naresh kumar k wrote:
CSProductsAction is form name and products is parameter and fillDetails is method in action class


-Which version of Struts are you on, I have used 1.1 and for me then anything like xxxxxxAction was action-name and not form form name.
-It was always 'execute' method of action where I would put my code into.
-why do you need parameters when you have an input box in place?
 
naresh kumar k
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the quik reply

I am using struts1.3.8
here form name means jsp page form : <html:form action="CSProductsAction" method="post">
<html:text property="productName" styleClass="login-txt" onblur="javascript: fillDetails(this);" ></html:text>
</html:form>
and i tried removing parameters also but no use

waiting for reply
naresh
 
naresh kumar k
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

please any please reply on this

waiting for reply
naresh
 
naresh kumar k
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i found the answer myself i made it working by changing like below

<head>
<script type="text/javascript">

function fillDetails(value1){

document.forms[0].action="CSProductsAction.do?products=fillDetails&productName="+value1;
document.forms[0].submit();

}
</script>
</head>
<body>
<html:form action="products" method="post">
<html:text property="productName" styleClass="login-txt" onblur="javascript: fillDetails(this.value);" ></html:text>
</html:form>

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic