programgirl
Programmer
I have written javascript code helps me filter keywords options in a <html:select> tag, in a JSP page.
(The reason I'm posting here is because my problem is with my javascript code.
so, in my JSP page I have the following as my textarea:
and the following is my javascript code, for doSelection, which helps me filter out words as I type them. The problem, however, is that after I erase a keyword, all my options will get selected - when I want them all deselected.
Also, when I'm entering keywords, I have to press the tab key to see the changes.
Is there a way I can see the change in the <html:select> tag as I go along? without having to enter any keys?
(The reason I'm posting here is because my problem is with my javascript code.
so, in my JSP page I have the following as my textarea:
Code:
<html:text property="metrics" style="query-table-item" size="40" styleId="metricsTxt" onchange="doSelection(this);" />
and the following is my javascript code, for doSelection, which helps me filter out words as I type them. The problem, however, is that after I erase a keyword, all my options will get selected - when I want them all deselected.
Also, when I'm entering keywords, I have to press the tab key to see the changes.
Is there a way I can see the change in the <html:select> tag as I go along? without having to enter any keys?
Code:
function doSelection (control)
{
// control is the textbox control
var typedText = control.value;
var selectControl = document.getElementById("metricsSelect");
//when keyword starts with the typed text
if(typedText==null)
{
for (var i=0; i<selectControl.options.length; i++)
{
if(selectControl.options[i].selected == true)
{
selectControl.options[i].selected = false;
}
}
}
else
{
if(document.getElementById("keywordSelect").checked)
{
for (var i=0; i<selectControl.options.length; i++)
{
if(selectControl.options[i].text.indexOf(typedText)==0)
{
selectControl.options[i].selected= true;
}
else
{
selectControl.options[i].selected = false; // unselects non-matches
}
}
}
//when keyword contains the typed text
if(document.getElementById("keywordSelect2").checked)
{
for (var i=0; i<selectControl.options.length; i++)
{
//if (typedText!=null && typedText==selectControl.options[i].text.substring(0,typedText.length+1))
if(selectControl.options[i].text.indexOf(typedText)>=0)
{
selectControl.options[i].selected= true;
}
else
{
selectControl.options[i].selected = false; // unselects non-matches
}
}
}
//when keyword ends with the typed text
if(document.getElementById("keywordSelect3").checked)
{
for (var i=0; i<selectControl.options.length; i++)
{
var pos = selectControl.options[i].text.indexOf(typedText);
if(selectControl.options[i].text.substring(pos)==typedText)
{
selectControl.options[i].selected= true;
}
else
{
selectControl.options[i].selected = false; // unselects non-matches
}
}
}
}
}