Connecting Tech Pros Worldwide Forums | Help | Site Map

Javascript : Select Box not functioning properly

Newbie
 
Join Date: Jun 2007
Posts: 4
#1: Jun 12 '07
Hi,

I'm new to javascript & trying to achieve a feature for Select Box to incorporate the feature of a textbox also. Like my select box has two events attached, onchange=smeFunction(var1.value) & onkeyup=findValue(this).

Expand|Select|Wrap|Line Numbers
  1. function findValue(sel) {
  2.  
  3.     var temp = true;
  4.     var k = String.fromCharCode(event.keyCode);
  5.     fnd += k;
  6.     for (var i=0; i<sel.options.length; i++) {
  7.     if (fnd.toUpperCase() == sel.options[i].text.substring(0, fnd.length).toUpperCase())
  8.                 {
  9.        sel.options[i].selected = true;
  10.        temp = false;
  11.       break;
  12.     }
  13.     }
  14.     if(temp) {
  15.                        fnd = "";
  16.                        fnd += k;
  17.                 }
  18.         return true;
  19.     }
Now the problem is findValue() is returning correct value in the select box, but the screen changes are reflected wrongly based on onchange event. Like if i have ATR, CLA, etc as options & i type CLA, the select box shows CLA but the screen shows the changes wrt ATR, which belongs to the last character presssed 'A' in 'CLA'. Kindly tell whether the function itself is wrong or i can do something to improve it.

Please help, i am in great need,
Thanks in advance.....

iam_clint's Avatar
Forum Leader
 
Join Date: Jul 2006
Location: Oklahoma
Posts: 1,076
#2: Jun 12 '07

re: Javascript : Select Box not functioning properly


the events are on the text box or the select box?
Newbie
 
Join Date: Jun 2007
Posts: 4
#3: Jun 13 '07

re: Javascript : Select Box not functioning properly


Quote:

Originally Posted by iam_clint

the events are on the text box or the select box?

Hi, the events are on the Select Box....
Reply


Similar JavaScript / Ajax / DHTML bytes