Zassałem sobie skrypt z pewnej stronki, który zamienia mi pole select w combobox. Jest mi to bardzo potrzebne do mojej strony. Nie ukrywam, że jeśli chodzi o js to jestem zielony. Problem polega na tym, że kiedy przy edycji pola nacisnę backspace przeglądarka (FF) cofa mi się do poprzedniej strony. Co trzebazrobić, żeby ten backspace działał normalnie?
<LINK href="general.css" rel="stylesheet" type="text/css"> <script LANGUAGE="JavaScript"> <!-- Original: Cyanide_7 (leo7278@hotmail.com) --> <!-- Web Site: <a href="http://www7.ewebcity.com/cyanide7" target="_blank">http://www7.ewebcity.com/cyanide7</a> --> var o = null; var isNN = (navigator.appName.indexOf("Netscape")!=-1); function beginEditing(menu) { finish(); if(menu[menu.selectedIndex].value == "n") { o = new Object(); o.editOption = menu[menu.selectedIndex]; o.editOption.old = o.editOption.text; o.editOption.text = "_"; menu.blur(); window.focus(); document.onkeypress = keyPressHandler; } function keyPressHandler(e){ var option = o.editOption; var keyCode = (isNN) ? e.which : event.keyCode; if(keyCode == 8 || keyCode == 37) option.text = option.text.substring(0,option.text.length-2) + "_"; else if (keyCode == 13) { finish(); } else option.text = option.text.substring(0,option.text.length-1) + String.fromCharCode(keyCode) + "_"; status = keyCode; } function finish() { if(o != null) { option = o.editOption; if(option.text.length > 1) option.text = option.text.substring(0,option.text.length-1); else option.text = option.old; document.onkeypress = null; o = null; } } } </script>
Już sobie poradziłem. Dla potomnych - należy dodać:
document.onkeydown = function(e) { k = e ? e.which : event.keyCode; if(k==8) return false; }