PDA

View Full Version : On the fly index searching.



Sticks
10-17-2004, 01:08 AM
Ok, you know those help lists you often see? Where as soon as your start typing the keyword you're looking for it jumps to that area?

As soon as you type s, it jumps down to the s's, then you hit t and it goes down to st's, etc etc.

Is this possible through form elements, or would this require a full blown, messy script?

Either way, please let me know. The set up I have now is a simple input text form on the left and a textarea on the right (used as placeholders, nothing more).

Any help would be appreciated, thanks!

Sticks
10-17-2004, 02:12 PM
<script>

function searchvalue(q) {
sr.value = q;
}

</script>

<input type=text onKeyUp="return searchvalue(this.value)">
<textarea rows=3 cols=15 name=sr readonly></textarea>

This is what I have so far. I simply made the input text (searchbox) execute the function after every keystroke. Then put a textarea in to check that the function is able to register every change. Works fine.

Now what I want to do is have a sort type loop that searches a list (probably use an array) and finds the closest match. A textarea won't work for the final index list because it doesn't allow for links, which I need.

Now what I need is a way for a sorting function to scroll down a list and highlight the closest match, then when the user clicks that item in the list, for the url to activate.

I'm not too java suave, but the more and more I work on it the less and less complicated it seems. But who knows. :)

Thanks for any help.

Sticks
10-17-2004, 03:42 PM
<script>
indexlist = new Array()
indexlist[0] = "Animal";
indexlist[1] = "Bat";
indexlist[2] = "Cat";
indexlist[3] = "Dog";
indexlist[4] = "Elephant";
indexlist[5] = "Fish";
indexlist[6] = "Goat";
indexlist[7] = "Horned Toad";
indexlist[8] = "You get the point";

var templist = new Array();

var i = 0;
for (i = 0; i < indexlist.length; i++) {
templist[i] = indexlist[i];

document.write(indexlist[i]+ '---' +templist[i]+ '<br>')
}


var foundslot = indexlist.length;
var t = 0;
function searchvalue(q) {
templist[foundslot] = q;
templist.sort();
for (t = 0; t < templist.length; t++) {
if (templist[t] == q) {
var foundslot = t;
}
}
sr.value = foundslot;
}

</script>


<input type=text name="sbox" value="heh" onKeyUp="return searchvalue(this.value)">
<textarea rows=3 cols=15 name=sr readonly>fff</textarea>


Alrighty. I've gotten this far. (made a temp array just to have some content run through the sorting) Problem with this code I can't solve, though. I have the sr.value set as the slot in which the entered 'q' value is found in the newly sorted array. But when the function is executed, that 'foundslot' value is given as undefined.

I have a feeling that though I may be making progress, I'm getting a lot messed up.

Sticks
10-17-2004, 06:45 PM
Nevermind, I finished it.

Surprised how few posts a forum linked to dynamicdrive would get (0!). Either way, was a good place to write down my progress.

cr3ative
10-17-2004, 07:19 PM
And your progress was interesting to watch.

Well done on completing the script, you might want to submit it.

cr3ative