Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

implementing dependent select boxes in struts1.2.9 and netbeans6.5

 
Bushra Binte
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,I am using netbeans6.5 with struts1.2.9 framework.In a jsp page when the user selects a value from the list,based on that value next <html:select> tag options has to be populated from the server.For this i am extending myaction class to dispatchAction.I have also added the method to be invoked when the user selects a value from the first select <html:select> LOV(list of values).

Now the problem is i have added a javascript function getSecondListOfValues() for an onchange event of the first select tag like this


<html:form action="/Search.do" method="POST">

<html:select property="firstSelect" onchange="getSecondListOfValues()">
<htmlptionsCollections ....>/<html;optionsCollections>
</html:select>

<html:select property="secondSelect" onchange="getThirdListOfValues()">
<htmlptionsCollections ....>/<html;optionsCollections>
</html:select>

<html:select property="thirdSelect" >
<htmlptionsCollections ....>/<html;optionsCollections>
</html:select>

<html:submit value="Submit"></html:submit>

</html:form>

In javascript function:

function getSecondListOfValues()
{

var firstSelectedValue = document.getElementById("firstSelect");

document.myform.action.value="SearchAction"; // This is the action name that extends DispatchAction class
document.myform.method.value="getSecondList"; // This is the method in SearchAction class

return true;
}

struts-config.xml:

<action name="searchFormBean"
path="/Search"
parameter="method"
type="com.training.reps.action.SearchAction">
<forward name="success" path="/SearchOrders.jsp"/>
</action>


The error:

I get javascript error saying myform is null or not an object.

I understand that i have not specified the form name in <html:form> tag as struts-html.tld doesnt let to specify and gets an error "name attribute is not declared in struts-html.tld".
 
rk palleru
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think you are assigning value to action and method.instead of that assign action direcly in javascript

In javascript function:

function getSecondListOfValues()
{

var firstSelectedValue = document.getElementById("firstSelect");

document.myform.action="SearchAction"; // This is the action name that extends DispatchAction class
document.myform.method="getSecondList"; // This is the method in SearchAction class

return true;
}
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@rk: If "action" and "method" are form properties then they need to have their *values* set, otherwise you'd just be overwriting DOM objects with strings--almost certainly not what's intended.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic