• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

manipulating ArrayList in javascript

 
Abhishek Kumar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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')
}
<%
}
%>

}

}
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the HTML/javascript fprum.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic