on 09-03-2010 1:00 AM
Dear SDN,
Pls help me in doing the code for the following scenario,
I have two dynamically populated drop downs with different sizes
now I want to loop through the firstdropdown and compare each value with the second drop down values,
if the first dropdown value does not exists in the second dropdown then it must return a message saying that the value does not exist in the second drop down..
I have tried using the followin code
for(int a =o;a<firstdropdown.size;a++){
string abc = firstdropdown.getelement(a).value
for(int b =o;a<seconddropdown.size;b++){
string xyz= seconddropdown.getelement(b).value
if(!abc .equals(xyz)
{
message abc is not found in the second dropdown
}
}
}
as it is a nested loop this code is returing some non relevant values
can some body pls help me in getting the correct code for comparing
Hi,
Try this piece of code:
boolean valueFound;
for(int i =0; i < firstdropdown.size; i++)
{
valueFound = false;
string firstValue = firstdropdown.getelement(i).value();
for(int j =0; j < seconddropdown.size; j++)
{
string secondValue = seconddropdown.getelement(j).value
if((firstValue.equals(secondValue))
{
valueFound = true;
break;
}
}
if(!valueFound)
{
//Report the message
}
}
Hope this helps you
Regards,
Poojith MV
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi when I am doing the comparions as the if((firstValue.equals(secondValue)).. I am getting the correct values,
but I need the value which is notequals to .. I am putting an else statement which has resulted in the following instead of A3 value ...
value A2
value A3
value A3
value A3
value A3
value A4
value A4
value A5
value A5
value A5
Hi,
Don't put any else statement. Just modify the code as below:
boolean valueFound;
for(int i =0; i < firstdropdown.size; i++)
{
valueFound = false;
string firstValue = firstdropdown.getelement(i).value();
for(int j =0; j < seconddropdown.size; j++)
{
string secondValue = seconddropdown.getelement(j).value
if((firstValue.equals(secondValue))
{
valueFound = true;
break;
}
}
if(!valueFound)
{
//Report the message
break; // Add this.
}
}
Hope this helps.
Regards,
Manoj
Hi,
Colud you please tell what non relevant values you are getting? Are you sure that you have written 0(zero) and not o(alphabet) in your for loop? Please re-check.
Regards,
Manoj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Try this Code
for(int a =o;a<firstdropdown.size;a++){
String found = "False";
string abc = firstdropdown.getelement(a).value
for(int b =o;b<seconddropdown.size;b++){
string xyz= seconddropdown.getelement(b).value
if(abc .equals(xyz)
{
found = "true"
}
}
if("false".equalingonecase(found))
{
Message Not found
}
else
{
Message found
}
Regards,
Raju Bonagiri
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.