views:

283

answers:

2

I am having a inner class(static) named SelectProdLineAssociationForm

I have also given a declaration like this--

public SelectProdLineAssociationForm selectProdLineAssociationForm =
  new SelectProdLineAssociationForm();

now on onclick event I want to set the field in the inner class a value so i am

document.forms[0].selectProdLineAssociationForm.selectedProdLineAssociationKey =
  selectedProdLineAssociationKey;

where selectedProdLineAssociationKey is passed in javascript method then it giving javascript error that document.forms[0].selectProdLineAssociationForm is undefined can any one plz tell me why and how it can be resolved

+1  A: 

you cannot access a java method or property from javascript. Javascript is purely client side.

one way you can do this is to print the property into a block, and then you can access it from javascript, e.g.:

<script>
var selectedProdLineAssociationKey  = '<%= SelectProdLineAssociationForm.selectProdLineAssociationForm.toString();=%>';
//...you can then use this variable else where in your script block
</script>

But you will not be able to change the value, unless you POST it back (and have the logic to change it on the serverside).

Chii
A: 

I am going for Struts here ... (as Massimiliano Fliri said, you have to provide more details).

You have to verify how your input tags were named in the HTML. Depending on how you wrote your JSP you might have an input tag named selectProdLineAssociationForm.selectedProdLineAssociationKey (one element).

This code :

document.forms[0].selectProdLineAssociationForm.selectedProdLineAssociationKey

says that your form contains selectProdLineAssociationForm that in turn contains selectedProdLineAssociationKey (two elements).

This is just a guess of what you are doing. You must provide more info if you want more help.

dpb