XCalibre1 Posted February 29, 2012 Share Posted February 29, 2012 Hello...new to the forum, so I hope that I"m posting in the right area. I have successfully *modified* created a shoutbox that works with Social Engine Websites. I have been looking for two days and have searched and implemented 100's of codes to try and figure out how I can just use the enter key to submit the message that others type in the shoutbox. I use jQuery, Ajax, Mysql, and PHP, but can't figure it out for the likes of me. I would really, really, really, appreciate the ability to get this fixed. Below is my code for my index.tpl, and my send_message.js. If you need anything else, please just let me know. Everything works. When you type your comment/message and press the send, then it sends it to the php file and to the database and then it recalls the database files and shows it in the shoutbox. Just can't get the enter key working. I'm sure it's something so simple that I"m going to hit myself over, but can't figure it out SEND_MESSAGE.JS $(function() { $('#newMessage').click(function() { document.newMessage.newMessageContent.value = ""; }); $('#newMessageSend').click(function() { var username = $("#username").val(); var message = $("#newMessageContent").val(); if (message == "" || message == "Enter your message here") { return false; } var dataString = 'username=' + username + '&message=' + message; $.ajax({ type: "POST", url: "/application/widgets/shoutbox/send_message.php", data: dataString, success: function() { document.newMessage.newMessageContent.value = ""; } }); }); }); INDEX.TPL - WITHOUT THE CSS <?php /** * SocialEngine * * @category Application_Widget * @package Widget * @copyright Copyright 2012 * @license Free * @author XCalibre */ ?> <SCRIPT LANGUAGE="JavaScript"> function open_pop(){ window.open('application/widgets/shoutbox/emot_box.html','mywin','left=20,top=20,width=470,height=230,toolbar=1,resizable=0'); } </SCRIPT> <html> <head> <script src="application/widgets/shoutbox/js/jQuery.js" type="text/javascript"></script> <body> <div class="chatBox"> <div class="user"> Welcome <input type="text" size="13px" name="username" id="username" value="<?php echo $this->translate('%1$s', $this->viewer()->getTitle()); ?>" readonly="readonly" style="border:hidden"/> </div> <div class="main"> </div> <div class="information"> Enter Text Below: </div> <div class="messageBox"> <form name ="newMessage" class="newMessage" action="" onclick=""> <div class="left"> <textarea name="newMessageContent" id="newMessageContent"></textarea> </div> <div class="smiley"> <input type="button" value = "Smilies" id="insertSmilies" onClick="open_pop()" /> </div <div class="right"> <input type="button" id="newMessageSend" value="Send" /> </div> </form> </div> <script src="application/widgets/shoutbox/js/refresh_message_log.js" type="text/javascript"></script> <script src="application/widgets/shoutbox/js/send_message.js" type="text/javascript"></script> <script src="application/widgets/shoutbox/js/protect.js" type="text/javascript"></script> </script> </body> </html> Please, any help would be appreciated. I think there's a conflict with the Ajax or something. I'm not sure. If I were, I wouldn't be here. LOL! Thank you all. Quote Link to comment https://forums.phpfreaks.com/topic/257998-code-not-working/ Share on other sites More sharing options...
gristoi Posted March 2, 2012 Share Posted March 2, 2012 You will more than likely to listen for the keypress events being triggered, then when the Enter key i used trigger the send, so something like this: var message = $('#newMessage'); var code =null; message.keypress(function(e) { code= (e.keyCode ? e.keyCode : e.which); if (code == 13) { //code 13 is the enter key // run the send message event } e.preventDefault(); }); so you will be basically binding the listener to any even to do with the message window. hope this helps point you in the right direction Quote Link to comment https://forums.phpfreaks.com/topic/257998-code-not-working/#findComment-1323096 Share on other sites More sharing options...
XCalibre1 Posted March 2, 2012 Author Share Posted March 2, 2012 Thank you for u're response. I just got a new desktop today, so I have a ton of things to transfer over from my 10 year old laptop. WOW, it's nice to have something faster. LOL... I"ll let you know what happens when I get back to my server and scripting. Thank you VERY much for providing me something to try. Blessings, X Quote Link to comment https://forums.phpfreaks.com/topic/257998-code-not-working/#findComment-1323228 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.