473,322 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Locating a string in a list

What is the most efficient method I could use to locate if a string is
already in my list? I need to verify if a name submitted by a user has
been submitted before and potentially my list can ve very long. Looping
the string through the whole list seems rather inefficient.

Thanks in advance for your suggestions.

Jul 23 '05 #1
5 1113
Lee
ef*****@epitome.com.sg said:

What is the most efficient method I could use to locate if a string is
already in my list? I need to verify if a name submitted by a user has
been submitted before and potentially my list can ve very long. Looping
the string through the whole list seems rather inefficient.


That's the sort of thing you should be doing on the server, with a database
lookup.

Jul 23 '05 #2
Yes, that's one option. I am programming in domino and I can do that
passing the "string"in an iframe and get the returned result but I was
just exploring if I can also do this with Javascript. by the way, this
operation is done by calling a O pixel iframe document.

Thanks

Jul 23 '05 #3
Yes, that's one option. I am programming in domino and I can do that
passing the "string"in an iframe and get the returned result but I was
just exploring if I can also do this with Javascript. by the way, this
operation is done by calling a O pixel iframe document.

Thanks

Jul 23 '05 #4
Yes, that's one option. I am programming in domino and I can do that
passing the "string"in an iframe and get the returned result but I was
just exploring if I can also do this with Javascript. by the way, this
operation is done by calling a O pixel iframe document.

Thanks

Jul 23 '05 #5
ef*****@epitome.com.sg wrote:
Yes, that's one option. I am programming in domino and I can do that
passing the "string"in an iframe and get the returned result but I was
just exploring if I can also do this with Javascript. by the way, this
operation is done by calling a O pixel iframe document.

Thanks


Here is a little script that illustrates a client-side check of the
list. Make sure you test again at the server, you can't be sure the
user has JavaScript enabled or that they aren't submitting their own
string back to your server.

I have used the option text, but you may want to use the option value
(if there is one). The match is between newline characters, you need
to select something that you put into the text area but isn't part of
the option values/text. The text area is readonly so that users
can't enter their own delimiters and mess-up the test.

You may use a comma separated set of values, but newlines may look
neater depending on what you put into the text area. Note that a
delimiter (\n) is added to the front of the string when testing, but
not used inside the text area. This should ensure you only match
entries, but please test thoroughly.
<script type="text/javascript">
function addToTA(txt,tgt){
var txtReg = new RegExp('\\n' + txt + '\\n');
if(txtReg.test('\n'+tgt.value)){
alert('You already chose ' + txt
+ '.\nSelect another value');
} else {
tgt.value += (tgt.value != '')?'\n'+txt : txt;
}
}
</script>
<form action="">
<select onchange="
addToTA(this[this.selectedIndex].value,this.form.theList)
";>
<option></option>
<option>Option 1</option>
<option>Option 2</option>
<option>Another Option 2</option>
<option>Option 22</option>
<option>Option 2 2</option>
<option>Another Option 2 2</option>
</select>
<textarea readonly name="theList" rows="10" cols="20"></textarea>
<br>
<input type="reset">
</form>

--
Rob
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: shawnk | last post by:
I've been writing an XML document analyzer that reads XML document and tracks the metrics of the document. Statistics such as a node count fo each type of XML node are printed out I am trying to...
2
by: hfk0 | last post by:
Hello, I'm a newbie here and was wondering anyone could help me with this. I have a simple ASP.NET 2 web application running perfectly fine with IIS and SQLServerExpress installed locally on...
5
by: BBands | last post by:
I'd like to see if a string exists, even approximately, in another. For example if "black" exists in "blakbird" or if "beatles" exists in "beatlemania". The application is to look though a long...
8
by: Dilip | last post by:
I have a situation where I have a bunch of strings stuffed into a vector. I need to run through each of them and locate approximate (or complete) matches to them in another file (which also...
1
by: steve1rm | last post by:
Hello, I have a problem trying to connect a remote sql server. The error: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may...
1
by: khandelwalk1 | last post by:
here is a java code, wich is supposed to read a file name from user n read its contents and display it, bt its nt working..ne1 dere cud help me...jus copy n paste dis code in a notepad file wid name...
4
by: Ty | last post by:
Hi all Short version of my problem: i have a Datagrid (Flexgrid from ComponentOne) with a Datatable as source. I need to search a row in the datatable, using a primary key column in the...
3
by: Reverend Fuzzy | last post by:
Does anyone know off-hand of a quick routine to identify and kill a running process by filename? My goal is to see if "outlook.exe" is still running after it terminates (which it sometimes...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.