AJAX Hitting Enter Problem
Posted: Wed Jun 13, 2007 5:06 pm
feyd | Please use
And here is the code for the form-y bit:
Notice i've also tried the onsubmit='' command too... which that doesn't work either.
Any ideas?
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Right, my AJAX built "instant messenger" thing I've been building from random snippets of code here, there and everywhere works fine when I press the "Send" button, though when I hit "Enter" on my keyboard it messes up. :/
When I press the "Send" button the URL stays as:
/im.php?timefrom=1181770983&towhom=1&keykey=tabruchi
Though when I press the "Enter" key on my keyboard is goes to:
im.php?
Weird? Yeah.
Here is the code for the function that "adds" the chat to the database:
[syntax="javascript"]function ajaxAddChat(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
ajaxRequest = new XMLHttpRequest();
} catch (e){
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
alert("Hmmm... something messed up. Message the Admin!");
return false;
}
}
}
var message = document.getElementById('message').value;
var theString = "?message=" + message;
ajaxRequest.open("GET", "add_chat.php" + theString + "&timefrom=<?php print $_GET[timefrom]; ?>&whoto=<?php print $_GET[towhom]; ?>&keykey=<?php print $_GET[keykey]; ?>", true);
ajaxRequest.send(null);
}Code: Select all
<tr><form name='myForm' onSubmit='ajaxAddChat()'>
<td width="100%" bgcolor="#3d3d3d" align="left" style="color:#FFFF00; font-weight:bold; text-decoration:none;">Message: <input type='text' id='message' onsubmit='ajaxAddChat()' size='50' /><input type='button' onclick='ajaxAddChat()' onsubmit='ajaxAddChat()' value='Send' /></td>
</form></tr>Any ideas?
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]