Jump to content

Code Not Working


XCalibre1

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.