0

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
  • It is not clear if you are using struts or some other framework which maps server side java objects to client side HTML... Can you provide more details? Commented Sep 9, 2009 at 11:48

2 Answers 2

1

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).

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.