473,405 Members | 2,344 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,405 software developers and data experts.

Problem with I.E list box

I have an annoying problem, that I am only recieving from IE. A user
can click a drop down box and type and IE will return a result, within
the select box, of a word beginning with the last letter that was
pressed. If a list box holds three values : Jon, Orange, and Nancy it
will jump to each one if Jon is typed. For instance, if Jon is typed.
IE will jump to J - Jon, then 0 - Orange, and will end up on N - Nancy.
I hope I explained it well enough. IE is the only problem I find this
in FireFox and Netscape do not do this.

Anyone know a work around?

P.S I do not want to use a text field to solve this, I want this to be
solved within the selection box

Thanks

Feb 14 '06 #1
6 1343
JonH wrote:
I have an annoying problem, that I am only recieving from IE. A user
can click a drop down box and type and IE will return a result, within
the select box, of a word beginning with the last letter that was
pressed. If a list box holds three values : Jon, Orange, and Nancy it
will jump to each one if Jon is typed. For instance, if Jon is typed.
IE will jump to J - Jon, then 0 - Orange, and will end up on N - Nancy.
I hope I explained it well enough. IE is the only problem I find this
in FireFox and Netscape do not do this.
I find Firefox 1.5 does exactly the same thing.

Anyone know a work around?
You can use script to 'work around' it, but it's a standard browser
behaviour so modifying it may confuse/annoy your users. Normally
attempting such modification has you chasing your tail to get consistent
behaviour across a reasonable selection of browsers.

P.S I do not want to use a text field to solve this, I want this to be
solved within the selection box


A text input is the most common solution (and likely the best) since the
user can see the text being matched and can modify it easily - search
for 'select type ahead' or similar in the CLJ archives.

Below is an example script that does what you ask, it can be optimised
significantly if you have long lists. Lightly tested in Firefox and IE.
<script type="text/javascript">

// Global to remember characters entered
var charsInput = null;

function textMatch(e, sel)
{
var currentSelIdx = sel.selectedIndex;
var e = e || window.event;
var let = String.fromCharCode(e.keyCode);
if (/[\w\d]/.test(let)){
charsInput = (charsInput)? charsInput + let : let;
}

var opts = sel.options;
var re = new RegExp('^' + charsInput,'i');;
for (var i=0, len=opts.length; i<len; ++i){
if (re.test(opts[i].text)){
sel.selectedIndex = i;
return;
}
}
sel.selectedIndex = currentSelIdx;
}

function cleanUp()
{
charsInput = null;
}

</script>

<form action="">
<div>
<select onkeyup="textMatch(event, this);"
onblur="cleanUp();" onclick="cleanUp();">
<option>Aardvarrk
<option>Adam
<option>Aden
<option>Adrian
<option>Ahmed
<option>Arthur
<option>Eve
<option>Evelyn
</select>
</div>
</form>


--
Rob
Feb 15 '06 #2
Rob,
Thank you very much for the reply. I have worked with the code for
about an hour, and I am still coming up with a problem

If a user selects(with a click) Jon, the code will stay on Jon or find
matches around it, so that works. Once that is done, the user has to
click another option in order for the script to restart, so to speak.
Is there a way, to restart the script without a click event?

Let me show you using your code

<form action="">
<div>
<select onkeyup="textMatch(event, this);"
onblur="cleanUp();" onclick="cleanUp();">
<option>Aardvarrk
<option>Adam
<option>Aden
<option>Adrian
<option>Ahmed
<option>Arthur
<option>Eve
<option>Evelyn
</select>
</div>
</form>

if I click Adam...I can cycle through and get to any name, once that is
done the script ends. Lets say the user ends up with Adrian, but
realized after the event that they wanted Eve...they would have to
click again if they did not want to search the list

Know a way around this?

If not, thank you for your Reply Rob, you gave a very helpful start

Feb 15 '06 #3
I found something that works really well

http://www.oreillynet.com/pub/a/java...nygoodman.html

Thanks again Rob, for the great start

Feb 15 '06 #4
JonH wrote:
I found something that works really well

http://www.oreillynet.com/pub/a/java...nygoodman.html

Thanks again Rob, for the great start


Goodman's stuff is generally not held in high regard (that is not to say
that mine is any better ;-) ). The typeahead function you linked to
specifically works only in browsers supporting the IE event model. There
is no good reason for that, you could adapt my code to do much the same
thing by adding a timeout to clear the search string if no keys are
pressed within a certain timespan.

You'll have a cross-browser solution that uses less than half the code
that Goodman's solution does.
--
Rob
Feb 16 '06 #5
RobG wrote:
[...]

You'll have a cross-browser solution that uses less than half the code
that Goodman's solution does.


What the heck. Maybe not half the code, but the stuff below works better
and in Firefox too. Note that it is a bit jerky in IE, that is because
IE will do its own match first, then fire the keyup. So each time you
press a key, IE moves to that option, then calls the function which
likely changes the option based on the search string at that point.

I've added lots of comments to help out.
<script type="text/javascript">

// Global to remember keystrokes
var taObj = {
charsIn : '',
lastIdx : 0,
delay : 1000,
timer : null,

// Sets a timer that will clear the search string if no
// keys pressed before delay ends
setTimer : function(){
clearTimeout(this.timer);
this.timer = setTimeout('taObj.cleanUp()',this.delay);
},

cleanUp : function(){this.charsIn = '';}
}

function typeAhead(e, sel)
{
// Get a reference to the event so can check character entered
var e = e || window.event;

// Get the character entered
var let = String.fromCharCode(e.keyCode);

// If it's a word character or digit, add it to the search string
if (/[\w\d]/.test(let)){
taObj.charsIn += let; //(''==taObj.charsIn)? let : taObj.charsIn;

// Start/restart the timer
taObj.setTimer();

} else {
return;
}

// Get a reference to the list of options
var opts = sel.options;

// Build a regular expression to check with
var re = new RegExp('^' + taObj.charsIn,'i');

// Find a matching option
for (var i=0, len=opts.length; i<len; ++i){

// If find a match, make it selected & return
if (re.test(opts[i].text)){
sel.selectedIndex = i;

// Remember last selected
taObj.lastIdx = i;
return;
}
}

// If no match found, keep last match
sel.selectedIndex = taObj.lastIdx;
}

</script>

<form action="">
<div>
<select onkeyup="typeAhead(event, this);">
<option>Aardvarrk
<option>Adam
<option>Aden
<option>Adrian
<option>Ahmed
<option>Arthur
<option>Eve
<option>EveEve
<option>Evelyn
<option>Terry
<option>Thomas
<option>Trevor
</select>
</div>
</form>


--
Rob
Feb 16 '06 #6
Thanks again Rob, works like a charm

Feb 16 '06 #7

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

Similar topics

5
by: Clifford W. Racz | last post by:
Has anyone solved the issue of translating lists in Word 2003 (WordML) into xHTML? I have been trying to get the nested table code for my XSLT to work for a while now, with no way to get the...
10
by: Michael Strorm | last post by:
Hi! I've been having problems with a DTD. Having had the Sun XML validator reject a document, I put it through 'xmllint' for more information. 'Xmllint' noted a problem with the DTD itself;...
2
by: Pascal Deparis | last post by:
Hi, I've got a problem with the DB2 Command Line Processor, in V8, FP1. The databases have been created on an AIX server (version 4.3.3). Have a look at this: >db2 ? list DB21034E The...
5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
57
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
1
by: cody | last post by:
I have a OOP problem with the well known pattern where objects containing an object which represents a list of subobjects. Now my problem is that the ctor of a subobject indirectly calls the...
14
by: rurpy | last post by:
Another Python docs problem... I was trying to use imp.find_module(). >>> imp.find_module("mymod", "./subdir") ImportError: No frozen submodule named ./subdir.mymod subdir/mymod.py...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
7
by: Fernando Barsoba | last post by:
Hi, After following the advice received in this list, I have isolated the memory leak problem I am having. I am also using MEMWATCH and I think it is working properly. The program does some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.