Searching the table with the given text

I am trying to get the results which match the given text in the textbox field from the table

for example:  if i give 'United States' or 'UNITED STATES' or 'united states', i am able to get a record from the table.

But if i give 'united' or 'states' or any combination in that string.  I do not get any record.

Is there any way to check to see if the table 'contains' the match

here is the snippet:
function convert(txtStr)
{
     var tmpName = txtStr.toLowerCase();
     var result  = "";
     var flag = 0;
     for (var i = 0; i < tmpName.length; i++)
     {
          if(i == 0){
              result += tmpName.charAt(i).toUpperCase()
              continue;
          }
           if (tmpName.charAt(i) == " "){
               result += tmpName.charAt(i)
                flag = 1;
               continue;
          }
          if(flag == 1){
              result += tmpName.charAt(i).toUpperCase();
              flag = 0;
          }
          else
              result += tmpName.charAt(i);
      }
      return result;
}

if (frmMain.txtName.value)
{
     var temp = convert(frmMain.txtName.value);
     query += "@Name='" + temp + "'";
}

any help would be greatly appreciated
anagm
anagmAsked:
Who is Participating?
 
YZlatConnect With a Mentor Commented:
translate(@Name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')
is the first argument of CONTAINS and
frmMain.txtName.value.toLowerCase() is the second. There is gotta be a comma between those and not a parenthesis
0
 
Weiping DuSenior Web DeveloperCommented:
Anagm

Does "like" work for you?
if (frmMain.txtName.value)
{
     var temp = convert(frmMain.txtName.value);
     query += "@Name like '%" + temp + "%'";
}
0
 
YZlatCommented:
you cannot search database with javascript
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
dave4dlCommented:
what you are looking for is the indexOf function.  This seaches through the string and returns the character position at which the string to search for is found (if it is found)

see http://wsabstract.com/javatutors/string4.shtml
0
 
anagmAuthor Commented:
It gives me an error:

i am searching by text 'United'

msxml3.dll: Expected token ']' found 'NAME'.

//Property[@Name -->like<-- '%United%' and @Language='English']
0
 
anagmAuthor Commented:
YZlat, i am searching the table
0
 
anagmAuthor Commented:
dave4dl, how should i use indexof function with my existing code
0
 
YZlatCommented:
your query should be something like that:

"//Property[contains(@Name,temp)]"
0
 
dave4dlCommented:
you should loop through your array of names (assuming you maintain an array) comparing each item to your target text using indexOf.

If you are running a query against a database from your javascript you should use the "LIKE" keyword with wildcards.  If the query is giving you an error, make sure final query it builds actually runs in whatever database system you are using.
0
 
anagmAuthor Commented:
can you please provide me with an example or a modification to my existing code.

0
 
anagmAuthor Commented:
YZLat,  

contains?

Should i use XPATH function: contains?

can you provide me with an example, please
0
 
YZlatCommented:
yes. the example is above
0
 
YZlatCommented:
Comment from YZlat
Date: 11/01/2006 08:12AM PST
ID: 17850511 Your Comment  


your query should be something like that:

"//Property[contains(@Name,temp)]"
0
 
anagmAuthor Commented:
the snipped to query the tabe is as follows:

var xpathQuery = "//Property"
if (query)
{
xpathQuery += "[" + query + "]";
}

how should i modify this?  YZLat, please help
                        
0
 
YZlatCommented:
something like this

var xpathQuery = "//Property"
query="contains(@Name,temp)"
if (query)
{
xpathQuery += "[" + query + "]";
}

0
 
YZlatCommented:
actually

 var(xpathQuery = "//Property")
        query = "contains(@Name," + temp + ")"
        If (query) Then
{
xpathQuery += "[" + query + "]";
}
0
 
anagmAuthor Commented:
YZlat,

function convert(txtStr)
{
     var tmpName = txtStr.toLowerCase();
     var result  = "";
     var flag = 0;
     for (var i = 0; i < tmpName.length; i++)
     {
          if(i == 0){
              result += tmpName.charAt(i).toUpperCase()
              continue;
          }
           if (tmpName.charAt(i) == " "){
               result += tmpName.charAt(i)
                flag = 1;
               continue;
          }
          if(flag == 1){
              result += tmpName.charAt(i).toUpperCase();
              flag = 0;
          }
          else
              result += tmpName.charAt(i);
      }
      return result;
}

if (frmMain.txtName.value)
{
     var temp = convert(frmMain.txtName.value);
     query += "@Name='" + temp + "'";
}

var xpathQuery = "//Property"
query = "contains(@Name," + temp + ")"
If (query)
{
xpathQuery += "[" + query + "]";
}

I get an error at (query = "contains(@Name," + temp + ")"

error message:  'Object expected'

need some more help please

0
 
anagmAuthor Commented:
actually, it is as follows;

function convert(txtStr)
{
     var tmpName = txtStr.toLowerCase();
     var result  = "";
     var flag = 0;
     for (var i = 0; i < tmpName.length; i++)
     {
          if(i == 0){
              result += tmpName.charAt(i).toUpperCase()
              continue;
          }
           if (tmpName.charAt(i) == " "){
               result += tmpName.charAt(i)
                flag = 1;
               continue;
          }
          if(flag == 1){
              result += tmpName.charAt(i).toUpperCase();
              flag = 0;
          }
          else
              result += tmpName.charAt(i);
      }
      return result;
}


function earch()
{
var query = "";
if (frmMain.txtName.value)
{
     var temp = convert(frmMain.txtName.value);
     query += "@Name='" + temp + "'";
}

var xpathQuery = "//Property"
query = "contains(@Name," + temp + ")"
If (query)
{
xpathQuery += "[" + query + "]";
}
}

I get an error at (query = "contains(@Name," + temp + ")"

error message:  'Object expected'

need some more help please
0
 
YZlatCommented:
this part

if (frmMain.txtName.value)
{
     var temp = convert(frmMain.txtName.value);
     query += "@Name='" + temp + "'";
}

var xpathQuery = "//Property"
query = "contains(@Name," + temp + ")"
If (query)
{
xpathQuery += "[" + query + "]";
}

should be


if (frmMain.txtName.value)
{
     var temp = convert(frmMain.txtName.value);
     query += "contains(@Name," + temp + ")"
}

var xpathQuery = "//Property"
If (query)
{
xpathQuery += "[" + query + "]";
}


0
 
dave4dlCommented:
ah, i should have recognized it.  I didnt realize you were using xpath.
0
 
anagmAuthor Commented:
I tried like that i get the following error:

msxml3.dll: Unknown method.
//Property[-->contains(@<--Name,United) and @Language='ENGLISH']

what modification i should do?
0
 
YZlatCommented:
try

if (frmMain.txtName.value)
{
     var temp = convert(frmMain.txtName.value);
     query += "contains(@Name,'" + temp + "')"
}

var xpathQuery = "//Property"
If (query)
{
xpathQuery += "[" + query + "]";
}
0
 
anagmAuthor Commented:
i get an error like this:

//Property[-->contains(@<--Name,'United') and @Language='ENGLISH']
0
 
anagmAuthor Commented:
I am trying like this:

if (frmMain.txtName.value)
{
query += "contains(translate(@Name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'))='" + frmMain.txtName.value.toLowerCase() +"'";
}

the contains() seems to work, but when i include the translate,

it gives me the error saying

msxml3.dll: Expected token ',' found ')'.

//Property[contains(translate(@Name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')-->)<--='united' and @Language='ENGLISH']

am i missing something in the code?

need some help
0
 
YZlatCommented:
it should be

if (frmMain.txtName.value)
{
query += "contains(translate(@Name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), frmMain.txtName.value.toLowerCase() )";}
0
 
anagmAuthor Commented:
thank you, YZlat
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.