Meaningless Drivel is fun!*
The moose likes HTML, CSS and JavaScript and the fly likes manipulating ArrayList in javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "manipulating ArrayList in javascript" Watch "manipulating ArrayList in javascript" New topic
Author

manipulating ArrayList in javascript

Abhishek Kumar
Ranch Hand

Joined: Dec 19, 2005
Posts: 52
i have five drop downs and i will be populating the second one only when the first one is properly selected and similarly third one will be populated only when the second one is properly selected.

The basic idea is i have arraylists for all the combos at the time of loading of the page.


i want to populate the combos on the basis of what is selected in the upper select box(or combo box).but i am not able to do it.I have made half way through.but some problems are there.


please see into it


sorry but the site suggested to change every (lesser than) with a < so i did it.so please change it on your machine.



code(javascript portion where i am manipulating the arrayLists in arrayLists scopes):-

function populateCustomer()
{
var i = 1;
<logic resent name='customerList' scope='request'>
document.relief.selectCustomer.options[i] = new Option("-----------------------Select Customer-------------------------","-1")
<logic:iterate name="customerList" id="customerList" scope="request">

document.relief.selectCustomer.options[i] = new Option("<bean:write name="customerList" property="customerName"/>","<bean:write name="customerList" property="customerId"/>");
i++;
</logic:iterate>
</logic resent>
}



function submitFormCustomer(){
var customerId = parseInt(document.relief.selectCustomer.value);
var i = 1;

document.relief.selectSLABucket.options.length = 0;
document.relief.selectSLABucket.options[0] = new Option('--------------Select SLA Bucket-----------------------------','-1')
alert("hiiiiiiiiiiiiiiiiiii" + customerId);
if(customerId==-1)
{
alert("No Customer");
document.relief.selectSLABucket.options.length = 0;
document.relief.selectSLABucket.options[0] = new Option('--------------Select SLA Bucket-----------------------------','-1');
}

else{
<%
ArrayList slaCategoryLists = (ArrayList)request.getAttribute("slaCategoryList");
Iterator itr = slaCategoryLists.iterator();
while(itr.hasNext()){
SLACategoryDataObject object = (SLACategoryDataObject)itr.next();
%>
if(customerId == <%=object.getCustomerId()%>
{
alert(i);
var abc = "<%=object.getCategoryName()%>";
alert("customerId"+customerId);
alert("customerId from Java"+<%=object.getCustomerId()%> ;
alert("getCategoryName from Java"+abc);
alert("getCategoryId from Java"+<%=object.getCategoryId()%> ;
document.relief.selectSLABucket.options[i] = new Option('<%=object.getCategoryName()%>', '<%=object.getCategoryId()%>');
i=i+1;
}
else{
document.relief.selectSLABucket.options.length = 0;
document.relief.selectSLABucket.options[0] = new Option('--------------Select SLA Bucket-----------------------------','-1');
}
<%
}
%>

}


}


function submitFormSLABucket(){
var customerId = parseInt(document.relief.selectCustomer.value);
var slaCategoryId = parseInt(document.relief.selectSLABucket.value);
alert(customerId);
alert(slaCategoryId);

var i = 1;
alert("hiiiiiiiiiiiiiiiiiii" +customerId+"ggffgsdfgsdfsd"+slaCategoryId);
if(customerId==-1||slaCategoryId==-1)
{
alert("No Customer or Category");
document.relief.selectSLA.options.length = 0;
document.relief.selectSLA.options[0] = new Option('------------------- Select SLA -----------------------------------','-1')
}

else{
<%
ArrayList slaLists = (ArrayList)request.getAttribute("slaList");
Iterator itr1 = slaLists.iterator();
while(itr1.hasNext()){
SLADataObject object = (SLADataObject)itr1.next();
%>

if(customerId == <%=object.getCustomerId()%>&&slaCategoryId==<%=object.getCategoryId()%>
{
alert(i);
alert("CustomerId From Java"+<%=object.getCustomerId()%> ;
alert("CategoryId From Java"+<%=object.getCategoryId()%> ;
alert("SLAName is::::::::"+'<%=object.getSlaName()%>');
alert("SLAID is::::::::"+<%=object.getSlaId()%> ;
document.relief.selectSLA.options[i] = new Option('<%=object.getSlaName()%>','<%=object.getSlaId()%>');
i=i+1;
}
else{
document.relief.selectSLA.options.length = 0;
document.relief.selectSLA.options[0] = new Option('------------------- Select SLA -----------------------------------','-1')
}
<%
}
%>

}

}


Thanks and Regards,

Abhishek Kumar
Software developer (Apps),
Arbor Networks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

Moved to the HTML/javascript fprum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

"AbhishekKumar Developer",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You can do something like http://www.javascriptkit.com/script/script2/multiplecombo.shtml

or

post back to the server to fil it in

or

use an Ajax (XHR) method

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: manipulating ArrayList in javascript
 
Similar Threads
Date - calulate new to x number of months?
javascript help
Urgent:: How to get values into a combo-box dynamically.......
Problem retrieving arraylist data in jsp page.Help needed :)
World Clock Problem