PDA

View Full Version : how to fires onchange event or how to release event keycode


jTrigger
02-12-2003, 05:03 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
author : jTrigger
email : kingii_21@yahoo.com
location : 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>

A1ien51
02-12-2003, 05:56 AM
so what you are asking is this?
How do I get the onchange to fire when the enter key is pushed??

If that is the case,
put the function the display() in the if statement of key13

if (keyPressed == 13){
window.status = 'Done'
display();
return;
}

Is that what you were asking??

jTrigger
02-13-2003, 02:49 AM
Originally posted by A1ien51
so what you are asking is this?
How do I get the onchange to fire when the enter key is pushed??

If that is the case,
put the function the display() in the if statement of key13

if (keyPressed == 13){
window.status = 'Done'
display();
return;
}

Is that what you were asking??

nope, assuming the adv_search() is from include file. and i want it to use for 50 pages with dropdown element and have onchange event with diff. function called for every dropdown element.I mean whatever the function called in onchage event still it'll be fires when entered pressed.

if (keyPressed == 13){
window.status = 'Done'
obj.onchage(); /*this is a sample only, this means that all function under this event will be executed. */
return;
}