Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-21-2008, 04:14 AM   PM User | #1
BlackCow
New to the CF scene

 
Join Date: Aug 2008
Location: Earth
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
BlackCow is an unknown quantity at this point
Tell PHP if a key is up or down with Javascript?

I know PHP well but I don't know much about Javascript. What I need to do is have Java Script detect if a key is down and tell PHP to do something when the key is down and then tell it to do something again when the key is back up.

I hope im not being to vague..

How would I go about doing this?
BlackCow is offline   Reply With Quote
Old 08-21-2008, 04:16 AM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
You will need to use ajax to let the server know what is happening. Javascript can't send something directly to php without ajax. For a beginner its not going to be easy.
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 08-21-2008, 04:59 AM   PM User | #3
BlackCow
New to the CF scene

 
Join Date: Aug 2008
Location: Earth
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
BlackCow is an unknown quantity at this point
Quote:
Originally Posted by _Aerospace_Eng_ View Post
You will need to use ajax to let the server know what is happening. Javascript can't send something directly to php without ajax. For a beginner its not going to be easy.
Is Ajax another language or is it related to Java Script? And could you give me a simple example? I'm not having much luck finding one on google.

Edit: Perhaps I could use Flash actionscript instead? I am more familiar with flash.

Last edited by BlackCow; 08-21-2008 at 07:16 AM..
BlackCow is offline   Reply With Quote
Old 08-21-2008, 09:03 AM   PM User | #4
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
Is Ajax another language or is it related to Java Script? And could you give me a simple example? I'm not having much luck finding one on google.
see http://en.wikipedia.org/wiki/AJAX
Sajax toolkit is fairly easy to customise.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 08-21-2008, 11:34 AM   PM User | #5
barkermn01
Regular Coder

 
Join Date: Nov 2007
Location: Leeds, UK
Posts: 514
Thanks: 24
Thanked 19 Times in 19 Posts
barkermn01 can only hope to improve
Flash Action Script 3 is verry simalar to Javascript
AJAX Basicly opens a Page without showing it no the Stages you can do is

Now Ajax has 3 main stages for you as a coder

1st, Connection to Page if you want to pass data to the page the easy way is to use $_GET[] so phpage.php?value1=value1

2nd is Waiting for the page ti send ready state so once php has done what it is supposed to

3rd Handle to Returned value

The Returned Value is any thing that is out putted i have once made a list that i seperateed using | then just do in javascript what you want to do with the value that is returned but to learn it

http://www.w3schools.com has some good tuts on how to implement AJAX
barkermn01 is offline   Reply With Quote
Old 08-21-2008, 09:53 PM   PM User | #6
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
actually, you don't need to use ajax to talk TO a php server.
you can make get requests using image tags, its far simpler to setup and very reliable. its a mainstay of web traffic monitors and advertisers.


example i whipped up:
Code:
<body>
<input type="button" 
   value="php relay test"
   onmousedown="phoneHome(1)"
   onmouseup="phoneHome(0)"    />

<script>

function phoneHome(buttonStatus){
   var i = new Image;
  var hitTime = (new Date()).getTime();
  var myPhpUrl = "changeStatus.php"
  i.src = myPhpUrl + "?button="+ buttonStatus + "&hitTime=" + hitTime;
}

</script>
</body>

you can then simply use the get/queryString features of php in your changeStatus.php (or whatever it is you are using) to catch the button parameter from the request. the example also passes the client time of the click, both for records and to guarantee a unique/uncached url for the request.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 08-22-2008, 12:48 AM   PM User | #7
BlackCow
New to the CF scene

 
Join Date: Aug 2008
Location: Earth
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
BlackCow is an unknown quantity at this point
Quote:
Originally Posted by rnd me View Post
actually, you don't need to use ajax to talk TO a php server.
you can make get requests using image tags, its far simpler to setup and very reliable. its a mainstay of web traffic monitors and advertisers.


example i whipped up:
Code:
<body>
<input type="button" 
   value="php relay test"
   onmousedown="phoneHome(1)"
   onmouseup="phoneHome(0)"    />

<script>

function phoneHome(buttonStatus){
   var i = new Image;
  var hitTime = (new Date()).getTime();
  var myPhpUrl = "changeStatus.php"
  i.src = myPhpUrl + "?button="+ buttonStatus + "&hitTime=" + hitTime;
}

</script>
</body>

you can then simply use the get/queryString features of php in your changeStatus.php (or whatever it is you are using) to catch the button parameter from the request. the example also passes the client time of the click, both for records and to guarantee a unique/uncached url for the request.
I'm still not quite getting it. I don't understand what it means to use image tags and I cant find W3C documentation on it.

It dosn't seem like it should be to complicated. I just need Java to detect if I am holding lets say the "A" key down. If its held down then send the string "im holding the A key down" to a PHP document. When I bring the key back up it needs to send another string to the PHP document saying "Im not holding the A key down"
BlackCow is offline   Reply With Quote
Old 08-25-2008, 04:47 PM   PM User | #8
lokeshshettyk
Regular Coder

 
lokeshshettyk's Avatar
 
Join Date: Aug 2008
Location: On the way to the moon!
Posts: 157
Thanks: 5
Thanked 20 Times in 20 Posts
lokeshshettyk is an unknown quantity at this point
Code:
This may sound more like a tutorial, however this may help if used effectively:)
Try this : http://www.ajaxf1.com/tutorial/ajax-php.html
lokeshshettyk is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:05 AM.


Advertisement
Log in to turn off these ads.