How would I... ?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

How would I... ?

Post by Jr »

Just curious if anyone knows how I would make text print out when I hold a spacific key and remove it when I release.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

i think it is onKeyPress() or something very similar
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

onKeyDown() & onKeyUp() ;)
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post by Jr »

Ok I got this to work so far except...

- how to make it work when a spacific key is pressed
- and how to make it so it comes up in the right spot when I scroll down on the page
(and doesn't pop-up off the screen where I can't see it)

Is that something with the Y direction maybe? (I really dont know) Please help...

Code: Select all

<script language=&quote;Javascript&quote;>
<!--
function toggleDiv(id,flagit) {
	if (flagit==&quote;1&quote;)
	{
		if (document.layers) document.layers&#1111;''+id+''].visibility = &quote;show&quote;
		else if (document.all) document.all&#1111;''+id+''].style.visibility = &quote;visible&quote;
		else if (document.getElementById) document.getElementById(''+id+'').style.visibility = &quote;visible&quote;
	}
	if (flagit==&quote;0&quote;)
	{
		if (document.layers) document.layers&#1111;''+id+''].visibility = &quote;hide&quote;
		else if (document.all) document.all&#1111;''+id+''].style.visibility = &quote;hidden&quote;
		else if (document.getElementById) document.getElementById(''+id+'').style.visibility = &quote;hidden&quote;
	}
}



function ViewData(user,ValueShow)
{
if(user.style.visibility==ValueShow)return true

	var mousex = window.event.x;		// mouse location capture event
	var mousey = window.event.y;		// mouse location capture event
	user.style.visibility = ValueShow;	// show or hide respective Example
	user.style.left = mousex - 50;		// place popup at the mouse X (left) location
	user.style.top = mousey;			// place popup at the mouse Y (top) location

}
//-->
</script>


<style>
	#example1 {
		position:absolute;
		width:150px;
		height:100px;
		color:blue;
		text-align:center;
		visibility:hidden;
		z-index:10;
	}
</style>

</head>
<body onKeyDown=&quote;ViewData(example1,'visible')&quote; onKeyUp=&quote;ViewData(example1,'hidden')&quote;>

<div id=&quote;example1&quote;>
This is the menu
</div>

</body>
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

You're going to need an event handler (easy with IE, not so easy with FF).

then check against the event to see which key was pressed (using the key code) and then do stuff accordingly.

ex for IE:

Code: Select all

function checkEvt(evt){
	if(evt.keyCode == 13 && evt.ctrlKey){
		//do stuff		
	}
}
<span onClick=&quote;checkEvt(event)&quote;>click me</span>
Post Reply