View Full Version : How to release event.keycode (onKeyress) so that onchange event can fires?
jTrigger
02-05-2003, 03:37 AM
Hi Everyone!
I create a incremental search in dropdown using javascript. My problem is
that the onchange event does not fires or triggered after the search finished or entered the selected options.
For example.
<select name="cboList" onKeypress="search()" onchange="gotoURL()">
The search() function call the event.keycode to capture the keyboard pressed.
How i'm goin' to release the event.keycode or onkeyPress event to fires the onchange event.
Can anyone throw some light on this?
joh6nn
02-05-2003, 04:56 AM
onchange requires two things in order to fire. the obvious part, is that the value of the element has to change. the non-obvious part, is that before the browser will check to see if the value has changed, you have to remove the focus from element.
i hope that helps. if that's not what you were looking for though, you're going to have to explain this a bit more clearly.
whammy
02-05-2003, 04:56 AM
Are you trying to do this (http://www.codingforums.com/showthread.php?s=&threadid=9865)? ;)
jTrigger
02-05-2003, 06:17 AM
here's my source code...also some of the characters like parentheses are not working...
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
/*
function name : incremental search
autored by: jTrigger
email : kingii_21@yahoo.com
locaion : Philippines
*/
var srcString = '';
var isSuccess = false;
var lastIndex = 0;
var lastTextSearch = '';
function adv_search(){
var keyPressed = event.keyCode;
var selElement = event.srcElement;
if (keyPressed == 13){
/* must release the event so that onchange event fires */
window.status = 'Done'
return;
}
else if (keyPressed == 27){
srcString = '';
lastTextSearch = '';
selElement.selectedIndex = 0;
}
else if (keyPressed == 8){
srcString = srcString.substr(0, srcString.length-1);
}
else if ((keyPressed > 31) && (keyPressed < 122))
{
if (srcString != ''){
if (srcString == lastTextSearch){
srcString = '';
lastTextSearch = '';
}
}
isSuccess = false;
selElement.selectedIndex = lastIndex;
srcString += String.fromCharCode(keyPressed);
srcString = srcString.toLowerCase();
window.status = 'search: '+ srcString
var regExpr = eval("/^" + srcString + "/");
for(var srcCtr = 0; srcCtr < selElement.length;srcCtr++){
selElementText = selElement.options[srcCtr].text.toLowerCase();
if (selElementText.search(regExpr) != -1)
{
selElement.selectedIndex = srcCtr;
lastTextSearch = selElementText;
lastIndex = srcCtr;
isSuccess = true;
}else{
lastIndex = 0;
}
}
if (!isSuccess){
srcString = '';
srcString = srcString.substr(0, srcString.length-1);
lastIndex = 0;
}
}
window.event.returnValue = false;
window.event.cancelBubble = true;
return true;
}
function resetGlobalVariables(){
srcString = '';
isSuccess = false;
lastIndex = 0;
lastTextSearch = '';
window.status = 'Done';
window.event.returnValue = true
}
function display(){
alert(cboList1.value);
}
//-->
</SCRIPT>
</head>
<body>
<select name="cboList1" id="cboList1" onKeyPress="adv_search()" onChange="display()" onFocus="resetGlobalVariables()">
<option value="0" selected>- Select Options -</option>
<option value="1">aaaa</option>
<option value="2">bbba</option>
<option value="3">bbbb</option>
<option value="4">cccc1 (x)</option>
<option value="5">cccc1's</option>
</select>
</body>
</html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.