Advertisement

06.01.2008 at 10:01PM PDT, ID: 23448936
[x]
Attachment Details

Keypress issues

Asked by nikdonovanau in JavaScript

Tags: javascript, IE

Hi , the following code moves a draggable Div (key_obj_id) using the arrow keys on the keyboard

How do i stop the browser from executing the default bahaviour of the arrow keys ? which is move the scroll bar.

preventDefault seems to be the function for IE..still confused on how to use it


Also i found this article which does exactly what i want but im not sure how to apply it to my code http://www.quirksmode.org/js/dragdrop.htmlStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
function KeyCheck(key_obj_id)
{
   var KeyID = event.keyCode;
   switch(KeyID)
   {
       case 37:
      document.info.KeyName.value = "Arrow Left"+key_obj_id;
	 var current_left = window.document.getElementById(key_obj_id).style.left;
	 current_left = (current_left.replace(/px/, ""));
	 current_left = parseInt(current_left)
	 new_left = current_left -1;
      window.document.getElementById(key_obj_id).style.left = new_left;
	  update_db(key_obj_id);
      break;
	  case 38:
      document.info.KeyName.value = "Arrow Up"+key_obj_id;
	 var current_top = window.document.getElementById(key_obj_id).style.top;
	 current_top = (current_top.replace(/px/, ""));
	 current_top = parseInt(current_top)
	 new_top = current_top -1;
      window.document.getElementById(key_obj_id).style.top = new_top;
	   update_db(key_obj_id);
      break;
	  case 39:
       document.info.KeyName.value = "Arrow Right"+key_obj_id;
	 var current_right = window.document.getElementById(key_obj_id).style.left;
	 current_right = (current_right.replace(/px/, ""));
	 current_right = parseInt(current_right)
	 new_right = current_right +1;
      window.document.getElementById(key_obj_id).style.left = new_right;
	   update_db(key_obj_id);
      break;
	  case 40:
        document.info.KeyName.value = "Arrow Down"+key_obj_id;
	 var current_bottom = window.document.getElementById(key_obj_id).style.top;
	 current_bottom = (current_bottom.replace(/px/, ""));
	 current_bottom = parseInt(current_bottom)
	 new_bottom = current_bottom +1;
	   window.document.getElementById(key_obj_id).style.top = new_bottom;
	    update_db(key_obj_id);
      break;   }
}
</script>
 
 
[+][-]06.02.2008 at 12:08AM PDT, ID: 21690066

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: javascript, IE
Sign Up Now!
Solution Provided By: mplungjan
Participating Experts: 2
Solution Grade: A
 
 
[+][-]06.02.2008 at 02:22AM PDT, ID: 21690544

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 03:01AM PDT, ID: 21690692

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 05:05AM PDT, ID: 21691216

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 04:43PM PDT, ID: 21696683

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.03.2008 at 07:43AM PDT, ID: 21700878

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.03.2008 at 11:51PM PDT, ID: 21707498

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06.07.2008 at 07:19PM PDT, ID: 21737313

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06.10.2008 at 11:47PM PDT, ID: 21757426

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628