By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,775 Members | 1,325 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,775 IT Pros & Developers. It's quick & easy.

Locating a string in a list

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.