Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by thomas on Apr 05, 2008 12:25
open dhtmlx forum
Can't get onKeyPressed event to work in combobox

I have a dhtmlx.com combo on my webpage. It works ok, it can find what I input, from the database, but the onKeyPressed doesnt work. I want some function to be executed when the enter key (number 13) is pressed, i mean submitting the input. But nothing happens when a key is pressed. When I do the same in the sample in dhtmlx, it logs my inputs.

Heres what on my page http://kodetslyst.dk/combotest.php :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>combobox test</title>
<script src="dhtmlx/dhtmlxCombo/codebase/dhtmlxcommon.js"></script>
<script src="dhtmlx/dhtmlxCombo/codebase/dhtmlxcombo.js"></script>
<link rel="STYLESHEET" type="text/css" href="dhtmlx/dhtmlxCombo/codebase/dhtmlxcombo.css">
<script type="text/javascript">
window.dhx_globalImgPath="dhtmlx/dhtmlxCombo/codebase/imgs/";
</script>

</head>

<body>
<div id="combo_zone" style="width:400px; height:30px;"></div>

<script type="text/javascript">
var z=new dhtmlXCombo("combo_zone","alfa",400);
z.enableFilteringMode(true,"dhtmlx/dhtmlxCombo/samples/filtering/100000/loadCombo.php",true,true);
combo.attachEvent("onKeyPressed",onKeyPressedFunc);
function onKeyPressedFunc(Gb){
alert(Gb);
};
</script>
</body></html>
Answer posted by Support on Apr 07, 2008 05:31
You have a typo in your code it must be
    z.attachEvent("onKeyPressed",onKeyPressedFunc);

Answer posted by thomas on Apr 07, 2008 13:53
Thanks

And how do I extract the value (the option), which is selected by pressing enter.

I've tried this in the file above, but it doesnt work:
function onKeyPressedFunc(Gb){if (Gb==13) {
var optval=z.getActualValue(combo_zone);
alert(optval);
}};
Answer posted by Support on Apr 08, 2008 02:27
In moment when onKeyPressed executed value is not selected yet ( value become available only during onChange event )
You can get the text entered in combo as
    z.getComboText();