Hi, I am trying to make a sound play on a keypress in php. I want it to sound when the user presses the enter button. But I have been having no luck with JavaScript, among others. I would be glad if you helped. Thanks.

Recommended Answers

All 6 Replies


Have you tried to use jQuery? It has an amazing library for key events. I haven't come across such a thing in PHP before.

I'll try JQuery.

But what is the script?

Here is some code if it helps (It's JavaScript):

Enter Chat and press enter
<div><input id=input placeholder=you-chat-here /></div>
Chat Output
<div id=box></div>
<div id=pubnub pub-key=demo sub-key=demo></div>
<script src=http://cdn.pubnub.com/pubnub-3.1.min.js></script>
var box = PUBNUB.$('box'), input = PUBNUB.$('input'), channel = 'chatlllll';
channel : channel,
callback : function(text) { box.innerHTML = (''+text).replace( /[<>]/g, '' ) + '<br>' + box.innerHTML; }
PUBNUB.bind( 'keyup', input, function(e) {
(e.keyCode || e.charCode) === 13 && PUBNUB.publish({
channel : channel, message : input.value, x : (input.value='')
} );

Hope that gives you guys an idea of what I'm trying to do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.