I am creating a chat system. I have a form with just a textarea where the chat message can be entered. I want the form to be submitted when the Enter key is pressed. So I found this script which works nicely when the script is on the same page as the form...
Code JavaScript:function submitenter(myfield,e) { var keycode; if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which; else return true; if (keycode == 13) { alert("Enter was pressed"); // myfield.form.submit(); return false; } else return true; } <textarea onKeyPress="return submitenter(this,event)"></textarea>
The problem is, I want my Javascript function to be located in the parent frameset and there is a child frame called "main" where the chat form goes. Also, the textarea is generated dynamically from that parent frame like this:
Code JavaScript:var chatTextarea = self.main.document.createElement("textarea");
Then I want to call the submitenter function from the frameset, something like this...
Code JavaScript:chatTextarea.onclick = function() { return submitenter(this,event) } ;
Trouble is, event is not defined anymore.
Also the line:
would reference the wrong page right?Code JavaScript:if (window.event) keycode = window.event.keyCode;
What are the correct frame references? Thanks.



Bookmarks