*
The moose likes Struts and the fly likes implementing dependent select boxes in struts1.2.9 and netbeans6.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "implementing dependent select boxes in struts1.2.9 and netbeans6.5" Watch "implementing dependent select boxes in struts1.2.9 and netbeans6.5" New topic
Author

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

Bushra Binte
Ranch Hand

Joined: Nov 07, 2006
Posts: 60
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

Joined: Feb 26, 2009
Posts: 22
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

Joined: Sep 29, 2008
Posts: 12617

@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.
 
jQuery in Action, 2nd edition
 
subject: implementing dependent select boxes in struts1.2.9 and netbeans6.5
 
Similar Threads
Struts HTML Taglib Issue
html select onchange
show different content after a choice in a combobox
html select onchange problem
how to populate dependent <html:select >