tkm Posted May 30, 2008 Share Posted May 30, 2008 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. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted May 30, 2008 Share Posted May 30, 2008 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? Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 30, 2008 Share Posted May 30, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.