Jump to content

Recommended Posts

Hello mates,

  I am trying to use javascript search method to look for a string. Here is my code:

 

for (;i<100;i++)
{
var search_txt=el.getValue();
var rg = new RegExp(search_txt,'i');
var cname=record.data.company_name;
if (cname.search(rg)>=0)
return true;
}

 

But my above code is not working. Can someone kindly point out what I am doing wrong. It will be a great help. Thank you.

Hello mates,

  I am trying to use javascript search method to look for a string. Here is my code:

 

for (;i<100;i++)
{
var search_txt=el.getValue();
var rg = new RegExp(search_txt,'i');
var cname=record.data.company_name;
if (cname.search(rg)>=0)
return true;
}

 

But my above code is not working. Can someone kindly point out what I am doing wrong. It will be a great help. Thank you.

 

You should probably show some more code.  Where does 'el' come from?  What does the getValue() function do?  Do you declare 'i' anywhere?  What do you mean by it 'not working'?  Is it returning the wrong string?  No string?  Is it iterating through all 100 elements without exiting when it should find the right one?

That code makes no sense to me, so I can't determine what it's supposed to do.

 

1. Where is the initial value of i defined?

2. The regular expression is crafted to search for the string 'i' not the variable i; so what is the purpose of the loop? It's just checking the same string over and over for the same search value

3. The code will return true if the search value is found. But, I see no "return false" if it does not.

 

Please explain what you are wanting the code to do along with some sample input and outputs you would expect to use.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.