Hi,

I put this question on http://www.codingforums.com but didn't get enough replies so I decided to put it here.

I have an array like the following and I want to search only those values against gAssessorsCompanyAssociationsArray array where a user has entered something in any textbox and where any dropdown value is not "- Select One -".

For example if a user has selected something in "Doctor Name" other than "- Select One -" then it should be part of my search against gAssessorsCompanyAssociationsArray array. If a user has entered something in "City" then it should be part of my search against gAssessorsCompanyAssociationsArray array.

I am storing if statement's expression is Profile_Filter variable and executing it using eval(which is not recommended). Is there any better approach than this?

My Array:
Code:
gAssessorsCompanyAssociationsArray[0] = new Object();   
gAssessorsCompanyAssociationsArray[0].DoctorName = gAssessorsInfoArray[j].DoctorName;   
gAssessorsCompanyAssociationsArray[0].DoctorLocation  = gAssessorsInfoArray[j].DoctorLocation;  
gAssessorsCompanyAssociationsArray[0].Specialty = gAssessorsInfoArray[j].Specialty; 
gAssessorsCompanyAssociationsArray[0].SubSpecialty = gAssessorsInfoArray[j].SubSpecialty;
gAssessorsCompanyAssociationsArray[0].City = gAssessorsInfoArray[j].City;   

gAssessorsCompanyAssociationsArray[1] = new Object();   
gAssessorsCompanyAssociationsArray[1].DoctorName = gAssessorsInfoArray[j].DoctorName;   
gAssessorsCompanyAssociationsArray[1].DoctorLocation  = gAssessorsInfoArray[j].DoctorLocation;  
gAssessorsCompanyAssociationsArray[1].Specialty = gAssessorsInfoArray[j].Specialty; 
gAssessorsCompanyAssociationsArray[1].SubSpecialty = gAssessorsInfoArray[j].SubSpecialty;
gAssessorsCompanyAssociationsArray[1].City = gAssessorsInfoArray[j].City;
My Code:
Code:
if($('#DoctorNameDropDown option:selected').text() != '- Select One -' || $('#DoctorLocationID').val() != '' || $('#SpecialtyDropDown option:selected').text() != '- Select One -' || $('#SubSpecialty').val() != '' || $('#City').val() != '')
            {               
                var Profile_Filter = '';

                if($('#DoctorNameDropDown option:selected').text() != '- Select One -')
                {                       
                    Profile_Filter += 'gAssessorsCompanyAssociationsArray[i].UserID == $("#DoctorNameDropDown option:selected").val()';                                                         
                }

                if($('#DoctorLocationID').val() != '' && $('#DoctorLocationID').val() != 0)
                {
                    if(Profile_Filter != '')                        
                        Profile_Filter += ' && ' + 'gAssessorsCompanyAssociationsArray[i].CompanyID == $("#DoctorLocationID").val()';
                    else
                        Profile_Filter += 'gAssessorsCompanyAssociationsArray[i].CompanyID == $("#DoctorLocationID").val()';
                }

                if($('#SpecialtyDropDown option:selected').text() != '- Select One -')
                {               
                    if(Profile_Filter != '')                        
                        Profile_Filter += ' && ' + 'gAssessorsCompanyAssociationsArray[i].AssessorSpecialty == $("#SpecialtyDropDown option:selected").val()';
                    else
                        Profile_Filter += 'gAssessorsCompanyAssociationsArray[i].AssessorSpecialty == $("#SpecialtyDropDown option:selected").val()';
                }

                if($('#SubSpecialty').val() != '' && $('#SubSpecialty').val() != 0)
                {                       
                    var SubSpecialty_Filter = '';
                    var SubSpecialty = $('#SubSpecialty').val().split(';');                         

                    for(var i = 0; i < SubSpecialty.length; i++)
                    {
                        if(SubSpecialty[i] == '')
                        {
                            SubSpecialty.splice(i, 1);
                            i--;                
                        }                                           
                    }                           

                    if(SubSpecialty.length > 1)
                    {                       
                        for(var j = 0; j < SubSpecialty.length; j++)
                        {
                            if(j == 0)
                            {
                                SubSpecialty_Filter += '(gAssessorsCompanyAssociationsArray[i].SubSpecialty.indexOf("' + SubSpecialty[j] + '") > -1';                                           
                            }
                            else
                            {
                                SubSpecialty_Filter += ' && gAssessorsCompanyAssociationsArray[i].SubSpecialty.indexOf("' + SubSpecialty[j] + '") > -1';                                        
                            }                                
                        }
                        SubSpecialty_Filter += ')';                     
                    }
                    else
                        SubSpecialty_Filter +=  '(gAssessorsCompanyAssociationsArray[i].SubSpecialty.indexOf("' + SubSpecialty[0] + '") > -1)'; 

                    if(Profile_Filter != '')                        
                        Profile_Filter += ' && ' + SubSpecialty_Filter; 
                    else
                        Profile_Filter += SubSpecialty_Filter;      
                }                       

                if($('#City').val() != '')
                {
                    if(Profile_Filter != '')                        
                        Profile_Filter += ' && ' + 'gAssessorsCompanyAssociationsArray[i].CompanyCity == $("#City").val()';
                    else
                        Profile_Filter += 'gAssessorsCompanyAssociationsArray[i].CompanyCity == $("#City").val()';
                }                   

                for(var i = 0; i < gAssessorsCompanyAssociationsArray.length; i++)
                {
                    if(eval(Profile_Filter))
                    {
                        gAssessorsIDSArray.push(gAssessorsCompanyAssociationsArray[i].UserID); 
                        gBookingsProfileArray.push(gAssessorsCompanyAssociationsArray[i]);                                      
                    }               
                }
        }